summaryrefslogtreecommitdiff
path: root/itests
diff options
context:
space:
mode:
Diffstat (limited to 'itests')
-rw-r--r--itests/test_bob.py35
-rw-r--r--itests/test_httpupload.py37
-rw-r--r--itests/test_ibb.py40
-rw-r--r--itests/test_pep.py64
4 files changed, 176 insertions, 0 deletions
diff --git a/itests/test_bob.py b/itests/test_bob.py
new file mode 100644
index 00000000..d0827df0
--- /dev/null
+++ b/itests/test_bob.py
@@ -0,0 +1,35 @@
+import asyncio
+import unittest
+from slixmpp.test.integration import SlixIntegration
+
+
+class TestBOB(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_0231'])
+ self.data = b'to' * 257
+ await self.connect_clients()
+
+ async def test_bob(self):
+ """Check we can send and receive a BOB."""
+ cid = self.clients[0]['xep_0231'].set_bob(
+ self.data,
+ 'image/jpeg',
+ )
+ recv = await self.clients[1]['xep_0231'].get_bob(
+ jid=self.clients[0].boundjid,
+ cid=cid,
+ )
+
+ self.assertEqual(self.data, recv['bob']['data'])
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestBOB)
diff --git a/itests/test_httpupload.py b/itests/test_httpupload.py
new file mode 100644
index 00000000..09e85c1d
--- /dev/null
+++ b/itests/test_httpupload.py
@@ -0,0 +1,37 @@
+try:
+ import aiohttp
+except ImportError:
+ aiohttp = None
+import unittest
+from io import BytesIO
+from slixmpp.test.integration import SlixIntegration
+
+
+class TestHTTPUpload(SlixIntegration):
+ async def asyncSetUp(self):
+ await super().asyncSetUp()
+ self.add_client(
+ self.envjid('CI_ACCOUNT1'),
+ self.envstr('CI_ACCOUNT1_PASSWORD'),
+ )
+ self.register_plugins(['xep_0363'])
+ # Minimal data, we do not want to clutter the remote server
+ self.data = b'tototo'
+ await self.connect_clients()
+
+
+ @unittest.skipIf(aiohttp is None, "aiohttp is not installed")
+ async def test_httpupload(self):
+ """Check we can upload a file properly."""
+ url = await self.clients[0]['xep_0363'].upload_file(
+ 'toto.txt',
+ input_file=BytesIO(self.data),
+ size=len(self.data),
+ )
+ async with aiohttp.ClientSession() as session:
+ async with session.get(url) as resp:
+ text = await resp.text()
+ self.assertEqual(text.encode('utf-8'), self.data)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestHTTPUpload)
diff --git a/itests/test_ibb.py b/itests/test_ibb.py
new file mode 100644
index 00000000..7cda8e22
--- /dev/null
+++ b/itests/test_ibb.py
@@ -0,0 +1,40 @@
+import asyncio
+import unittest
+from slixmpp.test.integration import SlixIntegration
+
+
+class TestIBB(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'),
+ )
+ config = {'block_size': 256, 'auto_accept': True}
+ self.register_plugins(['xep_0047'], [config])
+ self.data = b'to' * 257
+ await self.connect_clients()
+
+ async def test_ibb(self):
+ """Check we can send and receive data through ibb"""
+ coro_in = self.clients[1].wait_until('ibb_stream_start')
+ coro_out = self.clients[0]['xep_0047'].open_stream(
+ self.clients[1].boundjid,
+ sid='toto'
+ )
+ instream, outstream = await asyncio.gather(coro_in, coro_out)
+
+ async def send_and_close():
+ await outstream.sendall(self.data)
+ await outstream.close()
+
+ in_data, _ = await asyncio.gather(instream.gather(), send_and_close())
+
+ self.assertEqual(self.data, in_data)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestIBB)
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)