summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0030.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-03-07 19:48:07 +0100
committermathieui <mathieui@mathieui.net>2021-03-07 20:43:44 +0100
commit5a3ab2c5c13aea6761680a9ccc6cf53c133c9ac7 (patch)
tree2cf7221f8657883b01fe7b681f3bf5f13f7d8f29 /tests/test_stream_xep_0030.py
parent27cf97458b6876b462ac08c24ff0f69107004136 (diff)
downloadslixmpp-5a3ab2c5c13aea6761680a9ccc6cf53c133c9ac7.tar.gz
slixmpp-5a3ab2c5c13aea6761680a9ccc6cf53c133c9ac7.tar.bz2
slixmpp-5a3ab2c5c13aea6761680a9ccc6cf53c133c9ac7.tar.xz
slixmpp-5a3ab2c5c13aea6761680a9ccc6cf53c133c9ac7.zip
tests: enable and fix RSM test for XEP-0030
Diffstat (limited to 'tests/test_stream_xep_0030.py')
-rw-r--r--tests/test_stream_xep_0030.py82
1 files changed, 57 insertions, 25 deletions
diff --git a/tests/test_stream_xep_0030.py b/tests/test_stream_xep_0030.py
index 8cba8280..4cabfe38 100644
--- a/tests/test_stream_xep_0030.py
+++ b/tests/test_stream_xep_0030.py
@@ -512,30 +512,28 @@ class TestStreamDisco(SlixTest):
self.assertEqual(results, items,
"Unexpected items: %s" % results)
- '''
- def testGetItemsIterator(self):
+ def testGetItemsIterators(self):
"""Test interaction between XEP-0030 and XEP-0059 plugins."""
-
- raised_exceptions = []
+ iteration_finished = []
+ jids_found = set()
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
-
- def run_test():
- try:
- results.next()
- except StopIteration:
- raised_exceptions.append(True)
-
- t = threading.Thread(name="get_items_iterator",
- target=run_test)
- t.start()
-
+ async def run_test():
+ iterator = await self.xmpp['xep_0030'].get_items(
+ jid='foo@localhost',
+ node='bar',
+ iterator=True
+ )
+ iterator.amount = 10
+ async for page in iterator:
+ for item in page['disco_items']['items']:
+ jids_found.add(item[0])
+ iteration_finished.append(True)
+
+ test_run = self.xmpp.wrap(run_test())
+ self.wait_()
self.send("""
<iq id="2" type="get" to="foo@localhost">
<query xmlns="http://jabber.org/protocol/disco#items"
@@ -549,17 +547,51 @@ class TestStreamDisco(SlixTest):
self.recv("""
<iq id="2" type="result" to="tester@localhost">
<query xmlns="http://jabber.org/protocol/disco#items">
+ <item jid="a@b" node="1"/>
+ <item jid="b@b" node="2"/>
+ <item jid="c@b" node="3"/>
+ <item jid="d@b" node="4"/>
+ <item jid="e@b" node="5"/>
<set xmlns="http://jabber.org/protocol/rsm">
+ <first index='0'>a@b</first>
+ <last>e@b</last>
+ <count>10</count>
</set>
</query>
</iq>
""")
-
- t.join()
-
- self.assertEqual(raised_exceptions, [True],
- "StopIteration was not raised: %s" % raised_exceptions)
- '''
+ self.wait_()
+ self.send("""
+ <iq id="3" 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>
+ <after>e@b</after>
+ </set>
+ </query>
+ </iq>
+ """)
+ self.recv("""
+ <iq id="3" type="result" to="tester@localhost">
+ <query xmlns="http://jabber.org/protocol/disco#items">
+ <item jid="f@b" node="6"/>
+ <item jid="g@b" node="7"/>
+ <item jid="h@b" node="8"/>
+ <item jid="i@b" node="9"/>
+ <item jid="j@b" node="10"/>
+ <set xmlns="http://jabber.org/protocol/rsm">
+ <first index='5'>f@b</first>
+ <last>j@b</last>
+ <count>10</count>
+ </set>
+ </query>
+ </iq>
+ """)
+ expected_jids = {'%s@b' % i for i in 'abcdefghij'}
+ self.run_coro(test_run)
+ self.assertEqual(expected_jids, jids_found)
+ self.assertEqual(iteration_finished, [True])
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco)