Merge branch 'fix-moderation' into 'master'
XEP-0425: small fix & integration test See merge request poezio/slixmpp!86
This commit is contained in:
commit
6773dc4409
66
itests/test_moderate.py
Normal file
66
itests/test_moderate.py
Normal file
@ -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)
|
@ -9,6 +9,8 @@ from typing import Optional
|
|||||||
|
|
||||||
from slixmpp import JID, Message
|
from slixmpp import JID, Message
|
||||||
from slixmpp.exceptions import IqError, IqTimeout
|
from slixmpp.exceptions import IqError, IqTimeout
|
||||||
|
from slixmpp.xmlstream.handler import Callback
|
||||||
|
from slixmpp.xmlstream.matcher import StanzaPath
|
||||||
from slixmpp.plugins import BasePlugin
|
from slixmpp.plugins import BasePlugin
|
||||||
from slixmpp.plugins.xep_0425 import stanza
|
from slixmpp.plugins.xep_0425 import stanza
|
||||||
|
|
||||||
@ -24,10 +26,19 @@ class XEP_0425(BasePlugin):
|
|||||||
|
|
||||||
def plugin_init(self) -> None:
|
def plugin_init(self) -> None:
|
||||||
stanza.register_plugins()
|
stanza.register_plugins()
|
||||||
|
self.xmpp.register_handler(Callback(
|
||||||
|
'Moderated Message',
|
||||||
|
StanzaPath('message/apply_to/moderated/retract'),
|
||||||
|
self._handle_moderated,
|
||||||
|
))
|
||||||
|
|
||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
|
self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
|
||||||
|
|
||||||
|
def _handle_moderated(self, message: Message):
|
||||||
|
if message['type'] == 'groupchat':
|
||||||
|
self.xmpp.event('moderated_message', message)
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
|
self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
|
||||||
|
|
||||||
|
@ -42,5 +42,6 @@ def register_plugins():
|
|||||||
|
|
||||||
register_stanza_plugin(Message, Moderated)
|
register_stanza_plugin(Message, Moderated)
|
||||||
register_stanza_plugin(ApplyTo, Moderated)
|
register_stanza_plugin(ApplyTo, Moderated)
|
||||||
|
register_stanza_plugin(Moderated, Retract)
|
||||||
register_stanza_plugin(Moderated, Retracted)
|
register_stanza_plugin(Moderated, Retracted)
|
||||||
register_stanza_plugin(Moderated, OccupantId)
|
register_stanza_plugin(Moderated, OccupantId)
|
||||||
|
Loading…
Reference in New Issue
Block a user