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("""
1
""")
self.recv("""
item1
""")
self.send("""
1
item1
""")
self.recv("""
item2
""")
self.send("""
1
item2
""")
self.recv("""
""")
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("""
1
""")
self.recv("""
item2
""")
self.send("""
1
item2
""")
self.recv("""
item1
""")
self.send("""
1
item1
""")
self.recv("""
""")
t.join()
self.failUnless(self.items == ['item2', 'item1'])
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamSet)