summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stanza_xep_0369.py117
-rw-r--r--tests/test_stanza_xep_0405.py55
-rw-r--r--tests/test_stanza_xep_0421.py29
-rw-r--r--tests/test_stanza_xep_0444.py69
4 files changed, 270 insertions, 0 deletions
diff --git a/tests/test_stanza_xep_0369.py b/tests/test_stanza_xep_0369.py
new file mode 100644
index 00000000..8c3e2a6b
--- /dev/null
+++ b/tests/test_stanza_xep_0369.py
@@ -0,0 +1,117 @@
+import unittest
+from slixmpp import Iq, Message, JID
+from slixmpp.test import SlixTest
+from slixmpp.plugins.xep_0369 import stanza
+from slixmpp.plugins.xep_0060 import stanza as pstanza
+from slixmpp.plugins.xep_0369.mix_core import BASE_NODES
+
+
+class TestMIXStanza(SlixTest):
+
+ def setUp(self):
+ stanza.register_plugins()
+
+ def testMIXJoin(self):
+ """Test that data is converted to base64"""
+ iq = Iq()
+ iq['type'] = 'set'
+ for node in BASE_NODES:
+ sub = stanza.Subscribe()
+ sub['node'] = node
+ iq['mix_join'].append(sub)
+ iq['mix_join']['nick'] = 'Toto'
+
+ self.check(iq, """
+ <iq type="set">
+ <join xmlns='urn:xmpp:mix:core:1'>
+ <subscribe node='urn:xmpp:mix:nodes:messages'/>
+ <subscribe node='urn:xmpp:mix:nodes:participants'/>
+ <subscribe node='urn:xmpp:mix:nodes:info'/>
+ <nick>Toto</nick>
+ </join>
+ </iq>
+ """)
+
+ def testMIXUpdateSub(self):
+ iq = Iq()
+ iq['type'] = 'set'
+ iq.enable('mix_updatesub')
+ sub = stanza.Subscribe()
+ sub['node'] = 'urn:xmpp:mix:nodes:someothernode'
+ iq['mix_updatesub'].append(sub)
+
+ self.check(iq, """
+ <iq type="set">
+ <update-subscription xmlns='urn:xmpp:mix:core:1'>
+ <subscribe node='urn:xmpp:mix:nodes:someothernode'/>
+ </update-subscription>
+ </iq>
+ """)
+
+ def testMIXLeave(self):
+ iq = Iq()
+ iq['type'] = 'set'
+ iq.enable('mix_leave')
+
+ self.check(iq, """
+ <iq type="set">
+ <leave xmlns='urn:xmpp:mix:core:1'/>
+ </iq>
+ """)
+
+ def testMIXSetNick(self):
+ iq = Iq()
+ iq['type'] = 'set'
+ iq['mix_setnick']['nick'] = 'A nick'
+
+ self.check(iq, """
+ <iq type="set">
+ <setnick xmlns='urn:xmpp:mix:core:1'>
+ <nick>A nick</nick>
+ </setnick>
+ </iq>
+ """)
+
+ def testMIXMessage(self):
+ msg = Message()
+ msg['type'] = 'groupchat'
+ msg['body'] = 'This is a message body'
+ msg['mix']['nick'] = 'A nick'
+ msg['mix']['jid'] = JID('toto@example.com')
+
+ self.check(msg, """
+ <message type="groupchat">
+ <body>This is a message body</body>
+ <mix xmlns="urn:xmpp:mix:core:1">
+ <nick>A nick</nick>
+ <jid>toto@example.com</jid>
+ </mix>
+ </message>
+ """)
+
+ def testMIXNewParticipant(self):
+ msg = Message()
+ msg['pubsub_event']['items']['node'] = 'urn:xmpp:mix:nodes:participants'
+ item = pstanza.EventItem()
+ item['id'] = '123456'
+ item['mix_participant']['jid'] = JID('titi@example.com')
+ item['mix_participant']['nick'] = 'Titi'
+ msg['pubsub_event']['items'].append(item)
+
+ self.check(msg, """
+ <message>
+ <event xmlns='http://jabber.org/protocol/pubsub#event'>
+ <items node='urn:xmpp:mix:nodes:participants'>
+ <item id='123456'>
+ <participant xmlns='urn:xmpp:mix:core:1'>
+ <jid>titi@example.com</jid>
+ <nick>Titi</nick>
+ </participant>
+ </item>
+ </items>
+ </event>
+ </message>
+ """, use_values=False)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestMIXStanza)
diff --git a/tests/test_stanza_xep_0405.py b/tests/test_stanza_xep_0405.py
new file mode 100644
index 00000000..5d834cf1
--- /dev/null
+++ b/tests/test_stanza_xep_0405.py
@@ -0,0 +1,55 @@
+import unittest
+from slixmpp import Iq, Message, JID
+from slixmpp.test import SlixTest
+from slixmpp.plugins.xep_0405 import stanza
+from slixmpp.plugins.xep_0369 import stanza as mstanza
+from slixmpp.plugins.xep_0405.mix_pam import BASE_NODES
+
+
+class TestMIXPAMStanza(SlixTest):
+
+ def setUp(self):
+ stanza.register_plugins()
+ mstanza.register_plugins()
+
+ def testMIXPAMJoin(self):
+ """Test that data is converted to base64"""
+ iq = Iq()
+ iq['type'] = 'set'
+ iq['client_join']['channel'] = JID('mix@example.com')
+ for node in BASE_NODES:
+ sub = mstanza.Subscribe()
+ sub['node'] = node
+ iq['client_join']['mix_join'].append(sub)
+ iq['client_join']['mix_join']['nick'] = 'Toto'
+
+ self.check(iq, """
+ <iq type="set">
+ <client-join xmlns='urn:xmpp:mix:pam:2' channel='mix@example.com'>
+ <join xmlns='urn:xmpp:mix:core:1'>
+ <subscribe node='urn:xmpp:mix:nodes:messages'/>
+ <subscribe node='urn:xmpp:mix:nodes:participants'/>
+ <subscribe node='urn:xmpp:mix:nodes:info'/>
+ <nick>Toto</nick>
+ </join>
+ </client-join>
+ </iq>
+ """)
+
+
+ def testMIXPAMLeave(self):
+ iq = Iq()
+ iq['type'] = 'set'
+ iq['client_leave']['channel'] = JID('mix@example.com')
+ iq['client_leave'].enable('mix_leave')
+
+ self.check(iq, """
+ <iq type="set">
+ <client-leave xmlns='urn:xmpp:mix:pam:2' channel='mix@example.com'>
+ <leave xmlns='urn:xmpp:mix:core:1'/>
+ </client-leave>
+ </iq>
+ """)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestMIXPAMStanza)
diff --git a/tests/test_stanza_xep_0421.py b/tests/test_stanza_xep_0421.py
new file mode 100644
index 00000000..dbd7a592
--- /dev/null
+++ b/tests/test_stanza_xep_0421.py
@@ -0,0 +1,29 @@
+import unittest
+from slixmpp import JID, Message
+from slixmpp.test import SlixTest
+import slixmpp.plugins.xep_0421 as xep_0421
+from slixmpp.xmlstream import register_stanza_plugin
+
+
+class TestOccupantId(SlixTest):
+
+ def setUp(self):
+ register_stanza_plugin(Message, xep_0421.stanza.OccupantId)
+
+ def testReadOccupantId(self):
+ result = """
+ <message type='groupchat' from='foo@muc/nick1'>
+ <body>Some message</body>
+ <occupant-id xmlns='urn:xmpp:occupant-id:0' id='unique-id1'/>
+ </message>
+ """
+
+ msg = self.Message()
+ msg['type'] = 'groupchat'
+ msg['from'] = JID('foo@muc/nick1')
+ msg['body'] = 'Some message'
+ msg['occupant-id']['id'] = 'unique-id1'
+
+ self.check(msg, result)
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestOccupantId)
diff --git a/tests/test_stanza_xep_0444.py b/tests/test_stanza_xep_0444.py
new file mode 100644
index 00000000..b4d5739b
--- /dev/null
+++ b/tests/test_stanza_xep_0444.py
@@ -0,0 +1,69 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+import unittest
+from slixmpp import Message
+from slixmpp.test import SlixTest
+from slixmpp.plugins.xep_0444 import XEP_0444
+import slixmpp.plugins.xep_0444.stanza as stanza
+from slixmpp.xmlstream import register_stanza_plugin
+
+
+class TestReactions(SlixTest):
+
+ def setUp(self):
+ register_stanza_plugin(Message, stanza.Reactions)
+ register_stanza_plugin(stanza.Reactions, stanza.Reaction)
+
+ def testCreateReactions(self):
+ """Testing creating Reactions."""
+
+ xmlstring = """
+ <message>
+ <reactions xmlns="urn:xmpp:reactions:0" id="abcd">
+ <reaction>😃</reaction>
+ <reaction>🤗</reaction>
+ </reactions>
+ </message>
+ """
+
+ msg = self.Message()
+ msg['reactions']['id'] = 'abcd'
+ msg['reactions']['values'] = ['😃', '🤗']
+
+ self.check(msg, xmlstring, use_values=False)
+
+ self.assertEqual({'😃', '🤗'}, msg['reactions']['values'])
+
+
+ def testCreateReactionsUnrestricted(self):
+ """Testing creating Reactions with the extra all_chars arg."""
+
+ xmlstring = """
+ <message>
+ <reactions xmlns="urn:xmpp:reactions:0" id="abcd">
+ <reaction>😃</reaction>
+ <reaction>🤗</reaction>
+ <reaction>toto</reaction>
+ </reactions>
+ </message>
+ """
+
+ msg = self.Message()
+ msg['reactions']['id'] = 'abcd'
+ msg['reactions'].set_values(['😃', '🤗', 'toto'], all_chars=True)
+
+ self.check(msg, xmlstring, use_values=False)
+
+ self.assertEqual({'😃', '🤗'}, msg['reactions']['values'])
+ self.assertEqual({'😃', '🤗', 'toto'}, msg['reactions'].get_values(all_chars=True))
+ with self.assertRaises(ValueError):
+ msg['reactions'].set_values(['😃', '🤗', 'toto'], all_chars=False)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestReactions)