tests: enable and fix RSM test for XEP-0030
This commit is contained in:
parent
27cf97458b
commit
5a3ab2c5c1
2 changed files with 58 additions and 24 deletions
|
@ -123,6 +123,8 @@ class ResultIterator(AsyncIterator):
|
|||
self.query[self.interface]['rsm']['before'] = self.start
|
||||
else:
|
||||
self.query[self.interface]['rsm']['after'] = self.start
|
||||
elif self.reverse:
|
||||
self.query[self.interface]['rsm']['before'] = True
|
||||
|
||||
try:
|
||||
if self.pre_cb:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue