From 8eb756d55c575055cddf9f0bc6f5f1ae27486dc5 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 4 Dec 2020 00:23:13 +0100 Subject: XEP-0045: Add basic stanza tests --- tests/test_stanza_xep_0045.py | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/test_stanza_xep_0045.py (limited to 'tests/test_stanza_xep_0045.py') diff --git a/tests/test_stanza_xep_0045.py b/tests/test_stanza_xep_0045.py new file mode 100644 index 00000000..29dd75db --- /dev/null +++ b/tests/test_stanza_xep_0045.py @@ -0,0 +1,100 @@ +import unittest +from slixmpp import Message, Presence, Iq, JID +from slixmpp.test import SlixTest +from slixmpp.plugins.xep_0045.stanza import ( + MUCPresence, + MUCJoin, + MUCMessage, + MUCAdminQuery, + MUCAdminItem, + MUCHistory, + MUCOwnerQuery, + MUCOwnerDestroy, + MUCStatus, + MUCInvite, + MUCDecline, +) +from slixmpp.xmlstream import register_stanza_plugin, ET + + +class TestMUC(SlixTest): + + def setUp(self): + register_stanza_plugin(MUCMessage, MUCInvite) + register_stanza_plugin(MUCMessage, MUCDecline) + register_stanza_plugin(MUCMessage, MUCStatus) + register_stanza_plugin(MUCPresence, MUCStatus) + register_stanza_plugin(Presence, MUCPresence) + register_stanza_plugin(Presence, MUCJoin) + register_stanza_plugin(MUCJoin, MUCHistory) + register_stanza_plugin(Message, MUCMessage) + register_stanza_plugin(Iq, MUCAdminQuery) + register_stanza_plugin(Iq, MUCOwnerQuery) + register_stanza_plugin(MUCOwnerQuery, MUCOwnerDestroy) + register_stanza_plugin(MUCAdminQuery, MUCAdminItem, iterable=True) + + def testPresence(self): + presence = Presence() + presence['from'] = JID('muc@service/nick') + presence['muc']['affiliation'] = 'member' + presence['muc']['role'] = 'participant' + presence['muc']['status_codes'] = (100, 110, 210) + + self.check(presence, """ + + + + + + + + + """, use_values=False) + + + def testInvite(self): + message = Message() + message['from'] = 'user@server' + message['to'] = 'muc@service' + message['muc']['invite']['to'] = JID('user2@server2') + message['muc']['invite']['reason'] = 'Hey' + + self.check(message, """ + + + + Hey + + + + """, use_values=False) + + def testAdmin(self): + iq = Iq() + iq['id'] = '0' + iq['type'] = 'set' + iq.enable('mucadmin_query') + items = [ + ('none', 'test@example/a'), + ('owner', 'owner@example/a'), + ] + for aff, jid in items: + item_el = MUCAdminItem() + item_el['affiliation'] = aff + item_el['jid'] = jid + iq['mucadmin_query'].append(item_el) + self.check(iq, """ + + + + + + + """, use_values=False) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestMUC) -- cgit v1.2.3