summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLink Mauve <linkmauve@linkmauve.fr>2020-12-04 00:30:13 +0100
committerLink Mauve <linkmauve@linkmauve.fr>2020-12-04 00:30:13 +0100
commit922ad8d9ea32788039f303f8d96e553981b6ad57 (patch)
tree4509cc5568237c8bf421a393e9db943c1e448ab1
parent56f44dc47d53f8b387278fc7d13a11a914201df8 (diff)
parent8eb756d55c575055cddf9f0bc6f5f1ae27486dc5 (diff)
downloadslixmpp-922ad8d9ea32788039f303f8d96e553981b6ad57.tar.gz
slixmpp-922ad8d9ea32788039f303f8d96e553981b6ad57.tar.bz2
slixmpp-922ad8d9ea32788039f303f8d96e553981b6ad57.tar.xz
slixmpp-922ad8d9ea32788039f303f8d96e553981b6ad57.zip
Merge branch 'muc-more' into 'master'
MUC: Fix invite/decline issue and add basic stanza tests See merge request poezio/slixmpp!71
-rw-r--r--slixmpp/plugins/xep_0045/muc.py4
-rw-r--r--tests/test_overall.py6
-rw-r--r--tests/test_stanza_xep_0045.py100
3 files changed, 105 insertions, 5 deletions
diff --git a/slixmpp/plugins/xep_0045/muc.py b/slixmpp/plugins/xep_0045/muc.py
index 630112f3..82c07edd 100644
--- a/slixmpp/plugins/xep_0045/muc.py
+++ b/slixmpp/plugins/xep_0045/muc.py
@@ -31,6 +31,8 @@ from slixmpp.exceptions import IqError, IqTimeout
from slixmpp.plugins.xep_0045 import stanza
from slixmpp.plugins.xep_0045.stanza import (
+ MUCInvite,
+ MUCDecline,
MUCPresence,
MUCJoin,
MUCMessage,
@@ -64,6 +66,8 @@ class XEP_0045(BasePlugin):
self.rooms = {}
self.our_nicks = {}
# load MUC support in presence stanzas
+ 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)
diff --git a/tests/test_overall.py b/tests/test_overall.py
index 70c34a6a..16ac2f83 100644
--- a/tests/test_overall.py
+++ b/tests/test_overall.py
@@ -2,9 +2,9 @@ import os
import re
import sys
import unittest
-import tabnanny
import compileall
+
class TestOverall(unittest.TestCase):
"""
@@ -18,9 +18,5 @@ class TestOverall(unittest.TestCase):
rx = re.compile('/[.]svn|.*26.*')
self.assertTrue(compileall.compile_dir(src, rx=rx, quiet=True))
- def testTabNanny(self):
- """Testing that indentation is consistent"""
- self.assertFalse(tabnanny.check('..%sslixmpp' % os.sep))
-
suite = unittest.TestLoader().loadTestsFromTestCase(TestOverall)
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, """
+<presence from='muc@service/nick'>
+ <x xmlns='http://jabber.org/protocol/muc#user'>
+ <item affiliation='member' role='participant'/>
+ <status code='100'/>
+ <status code='110'/>
+ <status code='210'/>
+ </x>
+</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, """
+<message
+ from='user@server'
+ to='muc@service'>
+ <x xmlns='http://jabber.org/protocol/muc#user'>
+ <invite to='user2@server2'>
+ <reason>Hey</reason>
+ </invite>
+ </x>
+</message>
+ """, 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, """
+<iq type='set' id='0'>
+ <query xmlns='http://jabber.org/protocol/muc#admin'>
+ <item jid='test@example/a'
+ affiliation='none'/>
+ <item jid='owner@example/a'
+ affiliation='owner'/>
+ </query>
+</iq>
+ """, use_values=False)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestMUC)