summaryrefslogtreecommitdiff
path: root/itests/test_moderate.py
diff options
context:
space:
mode:
authorLink Mauve <linkmauve@linkmauve.fr>2020-12-12 14:51:25 +0100
committerLink Mauve <linkmauve@linkmauve.fr>2020-12-12 14:51:25 +0100
commit6773dc4409d5a8b304b296336090275703ba4687 (patch)
tree806b70da6a08f1569b575283c6335f5948a44939 /itests/test_moderate.py
parent71888b24a6d88c0396a08f5c8a28a79aa28e3669 (diff)
parentbf17c3270524fcec308be953681a4c5b75777755 (diff)
downloadslixmpp-6773dc4409d5a8b304b296336090275703ba4687.tar.gz
slixmpp-6773dc4409d5a8b304b296336090275703ba4687.tar.bz2
slixmpp-6773dc4409d5a8b304b296336090275703ba4687.tar.xz
slixmpp-6773dc4409d5a8b304b296336090275703ba4687.zip
Merge branch 'fix-moderation' into 'master'
XEP-0425: small fix & integration test See merge request poezio/slixmpp!86
Diffstat (limited to 'itests/test_moderate.py')
-rw-r--r--itests/test_moderate.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/itests/test_moderate.py b/itests/test_moderate.py
new file mode 100644
index 00000000..3e155ce4
--- /dev/null
+++ b/itests/test_moderate.py
@@ -0,0 +1,66 @@
+import asyncio
+import unittest
+import uuid
+from slixmpp import JID
+from slixmpp.test.integration import SlixIntegration
+
+UNIQUE = uuid.uuid4().hex
+
+
+class TestModerate(SlixIntegration):
+ async def asyncSetUp(self):
+ self.mucserver = self.envjid('CI_MUC_SERVER')
+ self.muc = JID('%s@%s' % (UNIQUE, self.mucserver))
+ 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_0425', 'xep_0359', 'xep_0045'])
+ await self.connect_clients()
+
+ async def setup_muc(self):
+ self.clients[0]['xep_0045'].join_muc(self.muc, 'client1')
+ presence = await self.clients[0].wait_until('muc::%s::got_online' % self.muc)
+ self.assertEqual(presence['muc']['affiliation'], 'owner')
+ # Send initial configuration
+ config = await self.clients[0]['xep_0045'].get_room_config(self.muc)
+ values = config.get_values()
+ values['muc#roomconfig_persistentroom'] = False
+ values['muc#roomconfig_membersonly'] = True
+ config['values'] = values
+ config.reply()
+ config = await self.clients[0]['xep_0045'].set_room_config(self.muc, config)
+
+ # Send affiliation list including client 2
+ await self.clients[0]['xep_0045'].send_affiliation_list(
+ self.muc,
+ [
+ (self.clients[1].boundjid.bare, 'member'),
+ ],
+ )
+ self.clients[1]['xep_0045'].join_muc(self.muc, 'client2')
+ await self.clients[1].wait_until('muc::%s::got_online' % self.muc)
+
+ async def test_moderate_msg(self):
+ """Try to moderate a message"""
+ await self.setup_muc()
+ msg = self.clients[1].make_message(
+ mto=self.muc, mtype='groupchat', mbody='Coucou'
+ )
+ msg.send()
+ msg_recv = await self.clients[0].wait_until('groupchat_message')
+ iqres, new_msg = await asyncio.gather(
+ self.clients[0]['xep_0425'].moderate(
+ self.muc,
+ id=msg_recv['id'],
+ reason='Your message is bad.',
+ ),
+ self.clients[1].wait_until('moderated_message')
+ )
+ self.assertTrue(new_msg['apply_to']['id'], msg_recv['id'])
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestModerate)