tests: enable and fix RSM test for XEP-0030

This commit is contained in:
mathieui 2021-03-07 19:48:07 +01:00
parent 27cf97458b
commit 5a3ab2c5c1
2 changed files with 58 additions and 24 deletions

View file

@ -123,6 +123,8 @@ class ResultIterator(AsyncIterator):
self.query[self.interface]['rsm']['before'] = self.start self.query[self.interface]['rsm']['before'] = self.start
else: else:
self.query[self.interface]['rsm']['after'] = self.start self.query[self.interface]['rsm']['after'] = self.start
elif self.reverse:
self.query[self.interface]['rsm']['before'] = True
try: try:
if self.pre_cb: if self.pre_cb:

View file

@ -512,30 +512,28 @@ class TestStreamDisco(SlixTest):
self.assertEqual(results, items, self.assertEqual(results, items,
"Unexpected items: %s" % results) "Unexpected items: %s" % results)
''' def testGetItemsIterators(self):
def testGetItemsIterator(self):
"""Test interaction between XEP-0030 and XEP-0059 plugins.""" """Test interaction between XEP-0030 and XEP-0059 plugins."""
iteration_finished = []
raised_exceptions = [] jids_found = set()
self.stream_start(mode='client', self.stream_start(mode='client',
plugins=['xep_0030', 'xep_0059']) plugins=['xep_0030', 'xep_0059'])
results = self.xmpp['xep_0030'].get_items(jid='foo@localhost', async def run_test():
iterator = await self.xmpp['xep_0030'].get_items(
jid='foo@localhost',
node='bar', node='bar',
iterator=True) iterator=True
results.amount = 10 )
iterator.amount = 10
def run_test(): async for page in iterator:
try: for item in page['disco_items']['items']:
results.next() jids_found.add(item[0])
except StopIteration: iteration_finished.append(True)
raised_exceptions.append(True)
t = threading.Thread(name="get_items_iterator",
target=run_test)
t.start()
test_run = self.xmpp.wrap(run_test())
self.wait_()
self.send(""" self.send("""
<iq id="2" type="get" to="foo@localhost"> <iq id="2" type="get" to="foo@localhost">
<query xmlns="http://jabber.org/protocol/disco#items" <query xmlns="http://jabber.org/protocol/disco#items"
@ -549,17 +547,51 @@ class TestStreamDisco(SlixTest):
self.recv(""" self.recv("""
<iq id="2" type="result" to="tester@localhost"> <iq id="2" type="result" to="tester@localhost">
<query xmlns="http://jabber.org/protocol/disco#items"> <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"> <set xmlns="http://jabber.org/protocol/rsm">
<first index='0'>a@b</first>
<last>e@b</last>
<count>10</count>
</set> </set>
</query> </query>
</iq> </iq>
""") """)
self.wait_()
t.join() self.send("""
<iq id="3" type="get" to="foo@localhost">
self.assertEqual(raised_exceptions, [True], <query xmlns="http://jabber.org/protocol/disco#items"
"StopIteration was not raised: %s" % raised_exceptions) 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) suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco)