2010-08-06 00:23:07 +00:00
|
|
|
from . sleektest import *
|
2010-06-27 21:40:06 +00:00
|
|
|
import sleekxmpp.plugins.xep_0030 as xep_0030
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
|
2010-06-27 21:40:06 +00:00
|
|
|
class TestDisco(SleekTest):
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2010-07-19 17:58:53 +00:00
|
|
|
registerStanzaPlugin(Iq, xep_0030.DiscoInfo)
|
|
|
|
registerStanzaPlugin(Iq, xep_0030.DiscoItems)
|
2010-08-06 00:23:07 +00:00
|
|
|
|
2010-05-26 13:40:12 +00:00
|
|
|
def testCreateInfoQueryNoNode(self):
|
|
|
|
"""Testing disco#info query with no node."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_info']['node'] = ''
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info" />
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testCreateInfoQueryWithNode(self):
|
|
|
|
"""Testing disco#info query with a node."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_info']['node'] = 'foo'
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info" node="foo" />
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testCreateInfoQueryNoNode(self):
|
|
|
|
"""Testing disco#items query with no node."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_items']['node'] = ''
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items" />
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testCreateItemsQueryWithNode(self):
|
|
|
|
"""Testing disco#items query with a node."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_items']['node'] = 'foo'
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items" node="foo" />
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testInfoIdentities(self):
|
|
|
|
"""Testing adding identities to disco#info."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_info']['node'] = 'foo'
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['disco_info'].addIdentity('conference', 'text', 'Chatroom')
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info" node="foo">
|
|
|
|
<identity category="conference" type="text" name="Chatroom" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testInfoFeatures(self):
|
|
|
|
"""Testing adding features to disco#info."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_info']['node'] = 'foo'
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['disco_info'].addFeature('foo')
|
|
|
|
iq['disco_info'].addFeature('bar')
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info" node="foo">
|
|
|
|
<feature var="foo" />
|
|
|
|
<feature var="bar" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testItems(self):
|
|
|
|
"""Testing adding features to disco#info."""
|
2010-06-27 21:40:06 +00:00
|
|
|
iq = self.Iq()
|
2010-05-26 13:40:12 +00:00
|
|
|
iq['id'] = "0"
|
|
|
|
iq['disco_items']['node'] = 'foo'
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['disco_items'].addItem('user@localhost')
|
|
|
|
iq['disco_items'].addItem('user@localhost', 'foo')
|
|
|
|
iq['disco_items'].addItem('user@localhost', 'bar', 'Testing')
|
2010-06-27 21:40:06 +00:00
|
|
|
|
|
|
|
self.checkIq(iq, """
|
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items" node="foo">
|
|
|
|
<item jid="user@localhost" />
|
|
|
|
<item node="foo" jid="user@localhost" />
|
|
|
|
<item node="bar" jid="user@localhost" name="Testing" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testAddRemoveIdentities(self):
|
|
|
|
"""Test adding and removing identities to disco#info stanza"""
|
2010-08-06 00:23:07 +00:00
|
|
|
ids = [('automation', 'commands', 'AdHoc'),
|
|
|
|
('conference', 'text', 'ChatRoom')]
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info = xep_0030.DiscoInfo()
|
|
|
|
info.addIdentity(*ids[0])
|
|
|
|
self.failUnless(info.getIdentities() == [ids[0]])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delIdentity('automation', 'commands')
|
|
|
|
self.failUnless(info.getIdentities() == [])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.setIdentities(ids)
|
|
|
|
self.failUnless(info.getIdentities() == ids)
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delIdentity('automation', 'commands')
|
|
|
|
self.failUnless(info.getIdentities() == [ids[1]])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delIdentities()
|
|
|
|
self.failUnless(info.getIdentities() == [])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testAddRemoveFeatures(self):
|
|
|
|
"""Test adding and removing features to disco#info stanza"""
|
2010-08-06 00:23:07 +00:00
|
|
|
features = ['foo', 'bar', 'baz']
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info = xep_0030.DiscoInfo()
|
|
|
|
info.addFeature(features[0])
|
|
|
|
self.failUnless(info.getFeatures() == [features[0]])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delFeature('foo')
|
|
|
|
self.failUnless(info.getFeatures() == [])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.setFeatures(features)
|
|
|
|
self.failUnless(info.getFeatures() == features)
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delFeature('bar')
|
|
|
|
self.failUnless(info.getFeatures() == ['foo', 'baz'])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delFeatures()
|
|
|
|
self.failUnless(info.getFeatures() == [])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
def testAddRemoveItems(self):
|
|
|
|
"""Test adding and removing items to disco#items stanza"""
|
2010-08-06 00:23:07 +00:00
|
|
|
items = [('user@localhost', None, None),
|
|
|
|
('user@localhost', 'foo', None),
|
|
|
|
('user@localhost', 'bar', 'Test')]
|
|
|
|
|
|
|
|
info = xep_0030.DiscoItems()
|
|
|
|
self.failUnless(True, ""+str(items[0]))
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.addItem(*(items[0]))
|
|
|
|
self.failUnless(info.getItems() == [items[0]], info.getItems())
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delItem('user@localhost')
|
|
|
|
self.failUnless(info.getItems() == [])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.setItems(items)
|
|
|
|
self.failUnless(info.getItems() == items)
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delItem('user@localhost', 'foo')
|
|
|
|
self.failUnless(info.getItems() == [items[0], items[2]])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
info.delItems()
|
|
|
|
self.failUnless(info.getItems() == [])
|
2010-05-26 13:40:12 +00:00
|
|
|
|
|
|
|
|
2010-06-27 21:40:06 +00:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestDisco)
|