diff options
author | Lance Stout <lancestout@gmail.com> | 2011-01-09 10:04:09 -0500 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-01-09 10:04:09 -0500 |
commit | 23e499998fc36b377e3adb77d3d59f885d94f21d (patch) | |
tree | 3dcef998633c65ea320cd2acfdaadb394e4ee773 /tests | |
parent | c156a4f723073e1e6394803b5bb1613227947266 (diff) | |
parent | acdf9e2d22dd604578f50d0a9b67c47e001da69f (diff) | |
download | slixmpp-23e499998fc36b377e3adb77d3d59f885d94f21d.tar.gz slixmpp-23e499998fc36b377e3adb77d3d59f885d94f21d.tar.bz2 slixmpp-23e499998fc36b377e3adb77d3d59f885d94f21d.tar.xz slixmpp-23e499998fc36b377e3adb77d3d59f885d94f21d.zip |
Merge branch 'develop' into roster
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_stanza_xep_0059.py | 106 | ||||
-rw-r--r-- | tests/test_stream_xep_0030.py | 48 | ||||
-rw-r--r-- | tests/test_stream_xep_0059.py | 162 | ||||
-rw-r--r-- | tests/test_stream_xep_0092.py | 69 |
4 files changed, 385 insertions, 0 deletions
diff --git a/tests/test_stanza_xep_0059.py b/tests/test_stanza_xep_0059.py new file mode 100644 index 00000000..913436a6 --- /dev/null +++ b/tests/test_stanza_xep_0059.py @@ -0,0 +1,106 @@ +from sleekxmpp.test import * +from sleekxmpp.plugins.xep_0059 import Set + + +class TestSetStanzas(SleekTest): + + def testSetFirstIndex(self): + s = Set() + s['first'] = 'id' + s.set_first_index('10') + self.check(s, """ + <set xmlns="http://jabber.org/protocol/rsm"> + <first index="10">id</first> + </set> + """) + + def testGetFirstIndex(self): + xml_string = """ + <set xmlns="http://jabber.org/protocol/rsm"> + <first index="10">id</first> + </set> + """ + s = Set(ET.fromstring(xml_string)) + expected = '10' + self.failUnless(s['first_index'] == expected) + + def testDelFirstIndex(self): + xml_string = """ + <set xmlns="http://jabber.org/protocol/rsm"> + <first index="10">id</first> + </set> + """ + s = Set(ET.fromstring(xml_string)) + del s['first_index'] + self.check(s, """ + <set xmlns="http://jabber.org/protocol/rsm"> + <first>id</first> + </set> + """) + + def testSetBefore(self): + s = Set() + s['before'] = True + self.check(s, """ + <set xmlns="http://jabber.org/protocol/rsm"> + <before /> + </set> + """) + + def testGetBefore(self): + xml_string = """ + <set xmlns="http://jabber.org/protocol/rsm"> + <before /> + </set> + """ + s = Set(ET.fromstring(xml_string)) + expected = True + self.failUnless(s['before'] == expected) + + def testGetBefore(self): + xml_string = """ + <set xmlns="http://jabber.org/protocol/rsm"> + <before /> + </set> + """ + s = Set(ET.fromstring(xml_string)) + del s['before'] + self.check(s, """ + <set xmlns="http://jabber.org/protocol/rsm"> + </set> + """) + + def testSetBeforeVal(self): + s = Set() + s['before'] = 'id' + self.check(s, """ + <set xmlns="http://jabber.org/protocol/rsm"> + <before>id</before> + </set> + """) + + def testGetBeforeVal(self): + xml_string = """ + <set xmlns="http://jabber.org/protocol/rsm"> + <before>id</before> + </set> + """ + s = Set(ET.fromstring(xml_string)) + expected = 'id' + self.failUnless(s['before'] == expected) + + def testGetBeforeVal(self): + xml_string = """ + <set xmlns="http://jabber.org/protocol/rsm"> + <before>id</before> + </set> + """ + s = Set(ET.fromstring(xml_string)) + del s['before'] + self.check(s, """ + <set xmlns="http://jabber.org/protocol/rsm"> + </set> + """) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestSetStanzas) diff --git a/tests/test_stream_xep_0030.py b/tests/test_stream_xep_0030.py index 25a41027..c960fc7a 100644 --- a/tests/test_stream_xep_0030.py +++ b/tests/test_stream_xep_0030.py @@ -1,3 +1,4 @@ +import sys import time import threading @@ -11,6 +12,7 @@ class TestStreamDisco(SleekTest): """ def tearDown(self): + sys.excepthook = sys.__excepthook__ self.stream_close() def testInfoEmptyDefaultNode(self): @@ -524,5 +526,51 @@ class TestStreamDisco(SleekTest): self.assertEqual(results, items, "Unexpected items: %s" % results) + def testGetItemsIterator(self): + """Test interaction between XEP-0030 and XEP-0059 plugins.""" + + raised_exceptions = [] + + def catch_exception(*args, **kwargs): + raised_exceptions.append(True) + + sys.excepthook = catch_exception + + self.stream_start(mode='client', + plugins=['xep_0030', 'xep_0059']) + + results = self.xmpp['xep_0030'].get_items(jid='foo@localhost', + node='bar', + iterator=True) + results.amount = 10 + + t = threading.Thread(name="get_items_iterator", + target=results.next) + t.start() + + self.send(""" + <iq id="2" type="get" to="foo@localhost"> + <query xmlns="http://jabber.org/protocol/disco#items" + node="bar"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>10</max> + </set> + </query> + </iq> + """) + self.recv(""" + <iq id="2" type="result" to="tester@localhost"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + </set> + </query> + </iq> + """) + + t.join() + + self.assertEqual(raised_exceptions, [True], + "StopIteration was not raised: %s" % raised_exceptions) + suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco) diff --git a/tests/test_stream_xep_0059.py b/tests/test_stream_xep_0059.py new file mode 100644 index 00000000..3a99842b --- /dev/null +++ b/tests/test_stream_xep_0059.py @@ -0,0 +1,162 @@ +import threading + +from sleekxmpp.test import * +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins.xep_0030 import DiscoItems +from sleekxmpp.plugins.xep_0059 import ResultIterator, Set + + +class TestStreamSet(SleekTest): + + def setUp(self): + register_stanza_plugin(DiscoItems, Set) + + def tearDown(self): + self.stream_close() + + def iter(self, rev=False): + q = self.xmpp.Iq() + q['type'] = 'get' + it = ResultIterator(q, 'disco_items', '1', reverse=rev) + for i in it: + for j in i['disco_items']['items']: + self.items.append(j[0]) + + def testResultIterator(self): + self.items = [] + self.stream_start(mode='client') + t = threading.Thread(target=self.iter) + t.start() + self.send(""" + <iq type="get" id="2"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>1</max> + </set> + </query> + </iq> + """) + self.recv(""" + <iq type="result" id="2"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="item1" /> + <set xmlns="http://jabber.org/protocol/rsm"> + <last>item1</last> + </set> + </query> + </iq> + """) + self.send(""" + <iq type="get" id="3"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>1</max> + <after>item1</after> + </set> + </query> + </iq> + """) + self.recv(""" + <iq type="result" id="3"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="item2" /> + <set xmlns="http://jabber.org/protocol/rsm"> + <last>item2</last> + </set> + </query> + </iq> + """) + self.send(""" + <iq type="get" id="4"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>1</max> + <after>item2</after> + </set> + </query> + </iq> + """) + self.recv(""" + <iq type="result" id="4"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="item2" /> + <set xmlns="http://jabber.org/protocol/rsm"> + </set> + </query> + </iq> + """) + t.join() + self.failUnless(self.items == ['item1', 'item2']) + + def testResultIteratorReverse(self): + self.items = [] + self.stream_start(mode='client') + + t = threading.Thread(target=self.iter, args=(True,)) + t.start() + + self.send(""" + <iq type="get" id="2"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>1</max> + <before /> + </set> + </query> + </iq> + """) + self.recv(""" + <iq type="result" id="2"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="item2" /> + <set xmlns="http://jabber.org/protocol/rsm"> + <first>item2</first> + </set> + </query> + </iq> + """) + self.send(""" + <iq type="get" id="3"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>1</max> + <before>item2</before> + </set> + </query> + </iq> + """) + self.recv(""" + <iq type="result" id="3"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="item1" /> + <set xmlns="http://jabber.org/protocol/rsm"> + <first>item1</first> + </set> + </query> + </iq> + """) + self.send(""" + <iq type="get" id="4"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <set xmlns="http://jabber.org/protocol/rsm"> + <max>1</max> + <before>item1</before> + </set> + </query> + </iq> + """) + self.recv(""" + <iq type="result" id="4"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="item1" /> + <set xmlns="http://jabber.org/protocol/rsm"> + </set> + </query> + </iq> + """) + + t.join() + self.failUnless(self.items == ['item2', 'item1']) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamSet) diff --git a/tests/test_stream_xep_0092.py b/tests/test_stream_xep_0092.py new file mode 100644 index 00000000..4a038558 --- /dev/null +++ b/tests/test_stream_xep_0092.py @@ -0,0 +1,69 @@ +import threading + +from sleekxmpp.test import * + + +class TestStreamSet(SleekTest): + + def tearDown(self): + self.stream_close() + + def testHandleSoftwareVersionRequest(self): + self.stream_start(mode='client', plugins=['xep_0030', 'xep_0092']) + + self.xmpp['xep_0092'].name = 'SleekXMPP' + self.xmpp['xep_0092'].version = 'dev' + self.xmpp['xep_0092'].os = 'Linux' + + self.recv(""" + <iq type="get" id="1"> + <query xmlns="jabber:iq:version" /> + </iq> + """) + + self.send(""" + <iq type="result" id="1"> + <query xmlns="jabber:iq:version"> + <name>SleekXMPP</name> + <version>dev</version> + <os>Linux</os> + </query> + </iq> + """) + + def testMakeSoftwareVersionRequest(self): + results = [] + + def query(): + r = self.xmpp['xep_0092'].get_version('foo@bar') + results.append(r) + + self.stream_start(mode='client', plugins=['xep_0030', 'xep_0092']) + + t = threading.Thread(target=query) + t.start() + + self.send(""" + <iq type="get" id="1" to="foo@bar"> + <query xmlns="jabber:iq:version" /> + </iq> + """) + + self.recv(""" + <iq type="result" id="1" from="foo@bar" to="tester@localhost"> + <query xmlns="jabber:iq:version"> + <name>Foo</name> + <version>1.0</version> + <os>Linux</os> + </query> + </iq> + """) + + t.join() + + expected = [{'name': 'Foo', 'version': '1.0', 'os':'Linux'}] + self.assertEqual(results, expected, + "Did not receive expected results: %s" % results) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamSet) |