diff options
author | mathieui <mathieui@mathieui.net> | 2021-02-13 19:57:31 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-02-13 20:23:21 +0100 |
commit | 3668e79fbc5fb0cadc98e965c45b284145c8d207 (patch) | |
tree | 7c97be0426b620788b4390a74371ca1039a62c26 | |
parent | febfb6d6cae8efdb728694cd7aab95f8267f04e8 (diff) | |
download | slixmpp-3668e79fbc5fb0cadc98e965c45b284145c8d207.tar.gz slixmpp-3668e79fbc5fb0cadc98e965c45b284145c8d207.tar.bz2 slixmpp-3668e79fbc5fb0cadc98e965c45b284145c8d207.tar.xz slixmpp-3668e79fbc5fb0cadc98e965c45b284145c8d207.zip |
itets: Add tests for 0222 and 0223
-rw-r--r-- | itests/test_pep.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/itests/test_pep.py b/itests/test_pep.py new file mode 100644 index 00000000..a674a348 --- /dev/null +++ b/itests/test_pep.py @@ -0,0 +1,64 @@ +import asyncio +import unittest +from uuid import uuid4 +from slixmpp.exceptions import IqError +from slixmpp.test.integration import SlixIntegration +from slixmpp.xmlstream import ElementBase, register_stanza_plugin +from slixmpp.plugins.xep_0060.stanza import Item + +class Mystanza(ElementBase): + namespace = 'random-ns' + name = 'mystanza' + plugin_attrib = 'mystanza' + interfaces = {'test'} + +register_stanza_plugin(Item, Mystanza) + +class TestPEP(SlixIntegration): + async def asyncSetUp(self): + await super().asyncSetUp() + self.add_client( + self.envjid('CI_ACCOUNT1'), + self.envstr('CI_ACCOUNT1_PASSWORD'), + ) + self.add_client( + self.envjid('CI_ACCOUNT2'), + self.envstr('CI_ACCOUNT2_PASSWORD'), + ) + self.register_plugins(['xep_0222', 'xep_0223']) + for client in self.clients: + client.auto_authorize = True + await self.connect_clients() + + async def test_pep_public(self): + """Check we can get and set public PEP data""" + stanza = Mystanza() + stanza['test'] = str(uuid4().hex) + await self.clients[0]['xep_0222'].store(stanza, id='toto') + fetched = await self.clients[0]['xep_0222'].retrieve( + stanza.namespace, + ) + fetched_stanza = fetched['pubsub']['items']['item']['mystanza'] + self.assertEqual(fetched_stanza['test'], stanza['test']) + + async def test_pep_private(self): + """Check we can get and set private PEP data""" + stanza = Mystanza() + stanza['test'] = str(uuid4().hex) + await self.clients[0]['xep_0223'].store( + stanza, node='private-random', id='toto' + ) + fetched = await self.clients[0]['xep_0223'].retrieve( + 'private-random', + ) + fetched_stanza = fetched['pubsub']['items']['item']['mystanza'] + self.assertEqual(fetched_stanza['test'], stanza['test']) + + with self.assertRaises(IqError): + fetched = await self.clients[1]['xep_0060'].get_item( + jid=self.clients[0].boundjid.bare, + node='private-random', + item_id='toto', + ) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestPEP) |