diff options
author | Lance Stout <lancestout@gmail.com> | 2010-10-07 10:58:13 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-10-07 10:58:13 -0400 |
commit | 0fffbb82000a1a6c3c23d62fedcbd8e8141f8994 (patch) | |
tree | 114c3767ccc13de3d0388b43cd357b90334f469a /tests/test_stanza_xep_0030.py | |
parent | 21c32c6e1cfd9b18e4c8320e0796e1d7e4b3f74c (diff) | |
download | slixmpp-0fffbb82000a1a6c3c23d62fedcbd8e8141f8994.tar.gz slixmpp-0fffbb82000a1a6c3c23d62fedcbd8e8141f8994.tar.bz2 slixmpp-0fffbb82000a1a6c3c23d62fedcbd8e8141f8994.tar.xz slixmpp-0fffbb82000a1a6c3c23d62fedcbd8e8141f8994.zip |
Unit test reorganization.
Moved SleekTest to sleekxmpp.test.
Organized test suites by their focus.
- Suites focused on testing stanza objects are named test_stanza_X.py
- Suites focused on testing stream behavior are name test_stream_X.py
Diffstat (limited to 'tests/test_stanza_xep_0030.py')
-rw-r--r-- | tests/test_stanza_xep_0030.py | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/tests/test_stanza_xep_0030.py b/tests/test_stanza_xep_0030.py new file mode 100644 index 00000000..bb7ee6a3 --- /dev/null +++ b/tests/test_stanza_xep_0030.py @@ -0,0 +1,176 @@ +from sleekxmpp.test import * +import sleekxmpp.plugins.xep_0030 as xep_0030 + + +class TestDisco(SleekTest): + + def setUp(self): + registerStanzaPlugin(Iq, xep_0030.DiscoInfo) + registerStanzaPlugin(Iq, xep_0030.DiscoItems) + + def testCreateInfoQueryNoNode(self): + """Testing disco#info query with no node.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_info']['node'] = '' + + self.check_iq(iq, """ + <iq id="0"> + <query xmlns="http://jabber.org/protocol/disco#info" /> + </iq> + """) + + def testCreateInfoQueryWithNode(self): + """Testing disco#info query with a node.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_info']['node'] = 'foo' + + self.check_iq(iq, """ + <iq id="0"> + <query xmlns="http://jabber.org/protocol/disco#info" node="foo" /> + </iq> + """) + + def testCreateInfoQueryNoNode(self): + """Testing disco#items query with no node.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_items']['node'] = '' + + self.check_iq(iq, """ + <iq id="0"> + <query xmlns="http://jabber.org/protocol/disco#items" /> + </iq> + """) + + def testCreateItemsQueryWithNode(self): + """Testing disco#items query with a node.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_items']['node'] = 'foo' + + self.check_iq(iq, """ + <iq id="0"> + <query xmlns="http://jabber.org/protocol/disco#items" node="foo" /> + </iq> + """) + + def testInfoIdentities(self): + """Testing adding identities to disco#info.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_info']['node'] = 'foo' + iq['disco_info'].addIdentity('conference', 'text', 'Chatroom') + + self.check_iq(iq, """ + <iq id="0"> + <query xmlns="http://jabber.org/protocol/disco#info" node="foo"> + <identity category="conference" type="text" name="Chatroom" /> + </query> + </iq> + """) + + def testInfoFeatures(self): + """Testing adding features to disco#info.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_info']['node'] = 'foo' + iq['disco_info'].addFeature('foo') + iq['disco_info'].addFeature('bar') + + self.check_iq(iq, """ + <iq id="0"> + <query xmlns="http://jabber.org/protocol/disco#info" node="foo"> + <feature var="foo" /> + <feature var="bar" /> + </query> + </iq> + """) + + def testItems(self): + """Testing adding features to disco#info.""" + iq = self.Iq() + iq['id'] = "0" + iq['disco_items']['node'] = 'foo' + iq['disco_items'].addItem('user@localhost') + iq['disco_items'].addItem('user@localhost', 'foo') + iq['disco_items'].addItem('user@localhost', 'bar', 'Testing') + + self.check_iq(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> + """) + + def testAddRemoveIdentities(self): + """Test adding and removing identities to disco#info stanza""" + ids = [('automation', 'commands', 'AdHoc'), + ('conference', 'text', 'ChatRoom')] + + info = xep_0030.DiscoInfo() + info.addIdentity(*ids[0]) + self.failUnless(info.getIdentities() == [ids[0]]) + + info.delIdentity('automation', 'commands') + self.failUnless(info.getIdentities() == []) + + info.setIdentities(ids) + self.failUnless(info.getIdentities() == ids) + + info.delIdentity('automation', 'commands') + self.failUnless(info.getIdentities() == [ids[1]]) + + info.delIdentities() + self.failUnless(info.getIdentities() == []) + + def testAddRemoveFeatures(self): + """Test adding and removing features to disco#info stanza""" + features = ['foo', 'bar', 'baz'] + + info = xep_0030.DiscoInfo() + info.addFeature(features[0]) + self.failUnless(info.getFeatures() == [features[0]]) + + info.delFeature('foo') + self.failUnless(info.getFeatures() == []) + + info.setFeatures(features) + self.failUnless(info.getFeatures() == features) + + info.delFeature('bar') + self.failUnless(info.getFeatures() == ['foo', 'baz']) + + info.delFeatures() + self.failUnless(info.getFeatures() == []) + + def testAddRemoveItems(self): + """Test adding and removing items to disco#items stanza""" + items = [('user@localhost', None, None), + ('user@localhost', 'foo', None), + ('user@localhost', 'bar', 'Test')] + + info = xep_0030.DiscoItems() + self.failUnless(True, ""+str(items[0])) + + info.addItem(*(items[0])) + self.failUnless(info.getItems() == [items[0]], info.getItems()) + + info.delItem('user@localhost') + self.failUnless(info.getItems() == []) + + info.setItems(items) + self.failUnless(info.getItems() == items) + + info.delItem('user@localhost', 'foo') + self.failUnless(info.getItems() == [items[0], items[2]]) + + info.delItems() + self.failUnless(info.getItems() == []) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestDisco) |