summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0059.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-01-08 10:58:47 -0500
committerLance Stout <lancestout@gmail.com>2011-01-08 10:58:47 -0500
commita8e36574873e86d75a5ca796ce212c10dd3266ff (patch)
treec113d4bf769d3a70350d8cec0c8ba8db18ce3fd0 /tests/test_stream_xep_0059.py
parent13a2f719f4e31e48df05a5df8fa470d704e15528 (diff)
downloadslixmpp-a8e36574873e86d75a5ca796ce212c10dd3266ff.tar.gz
slixmpp-a8e36574873e86d75a5ca796ce212c10dd3266ff.tar.bz2
slixmpp-a8e36574873e86d75a5ca796ce212c10dd3266ff.tar.xz
slixmpp-a8e36574873e86d75a5ca796ce212c10dd3266ff.zip
Added new XEP-0059 plugin.
Contributed by Erik Reuterborg Larsson (who).
Diffstat (limited to 'tests/test_stream_xep_0059.py')
-rw-r--r--tests/test_stream_xep_0059.py162
1 files changed, 162 insertions, 0 deletions
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)