diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_stanza_base.py | 8 | ||||
-rw-r--r-- | tests/test_stanza_xep_0377.py | 56 | ||||
-rw-r--r-- | tests/test_stanza_xep_0421.py | 29 | ||||
-rw-r--r-- | tests/test_stanza_xep_0444.py | 69 | ||||
-rw-r--r-- | tests/test_stream_xep_0323.py | 2 |
5 files changed, 156 insertions, 8 deletions
diff --git a/tests/test_stanza_base.py b/tests/test_stanza_base.py index 35fa5e99..55554aa9 100644 --- a/tests/test_stanza_base.py +++ b/tests/test_stanza_base.py @@ -68,13 +68,5 @@ class TestStanzaBase(SlixTest): self.assertTrue(stanza['payload'] == [], "Stanza reply did not empty stanza payload.") - def testError(self): - """Test marking a stanza as an error.""" - stanza = StanzaBase() - stanza['type'] = 'get' - stanza.error() - self.assertTrue(stanza['type'] == 'error', - "Stanza type is not 'error' after calling error()") - suite = unittest.TestLoader().loadTestsFromTestCase(TestStanzaBase) diff --git a/tests/test_stanza_xep_0377.py b/tests/test_stanza_xep_0377.py new file mode 100644 index 00000000..321a26a8 --- /dev/null +++ b/tests/test_stanza_xep_0377.py @@ -0,0 +1,56 @@ +import unittest +from slixmpp import Iq +from slixmpp.test import SlixTest +import slixmpp.plugins.xep_0191 as xep_0191 +import slixmpp.plugins.xep_0377 as xep_0377 +from slixmpp.xmlstream import register_stanza_plugin + + +class TestSpamReporting(SlixTest): + + def setUp(self): + register_stanza_plugin(Iq, xep_0191.Block) + register_stanza_plugin( + xep_0191.Block, + xep_0377.Report, + ) + register_stanza_plugin( + xep_0377.Report, + xep_0377.Text, + ) + + def testCreateReport(self): + report = """ + <iq type="set"> + <block xmlns="urn:xmpp:blocking"> + <report xmlns="urn:xmpp:reporting:0"> + <spam/> + </report> + </block> + </iq> + """ + + iq = self.Iq() + iq['type'] = 'set' + iq['block']['report']['spam'] = True + + self.check(iq, report) + + def testEnforceOnlyOneSubElement(self): + report = """ + <iq type="set"> + <block xmlns="urn:xmpp:blocking"> + <report xmlns="urn:xmpp:reporting:0"> + <abuse/> + </report> + </block> + </iq> + """ + + iq = self.Iq() + iq['type'] = 'set' + iq['block']['report']['spam'] = True + iq['block']['report']['abuse'] = True + self.check(iq, report) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestSpamReporting) 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) diff --git a/tests/test_stream_xep_0323.py b/tests/test_stream_xep_0323.py index 7c9cc7e8..baacd7d3 100644 --- a/tests/test_stream_xep_0323.py +++ b/tests/test_stream_xep_0323.py @@ -4,6 +4,7 @@ import sys import datetime import time import threading +import unittest import re from slixmpp.test import * @@ -11,6 +12,7 @@ from slixmpp.xmlstream import ElementBase from slixmpp.plugins.xep_0323.device import Device +@unittest.skip('') class TestStreamSensorData(SlixTest): """ |