From fdb0749cd14ea9480687d5e243ec8fc81731e4dd Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 4 Dec 2020 18:45:06 +0100 Subject: XEP-0422,0424,0425,0439: Add basic stanza tests --- tests/test_stanza_xep_0422.py | 33 +++++++++++++++++++++++++ tests/test_stanza_xep_0424.py | 39 +++++++++++++++++++++++++++++ tests/test_stanza_xep_0425.py | 47 +++++++++++++++++++++++++++++++++++ tests/test_stanza_xep_0439.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 tests/test_stanza_xep_0422.py create mode 100644 tests/test_stanza_xep_0424.py create mode 100644 tests/test_stanza_xep_0425.py create mode 100644 tests/test_stanza_xep_0439.py (limited to 'tests') diff --git a/tests/test_stanza_xep_0422.py b/tests/test_stanza_xep_0422.py new file mode 100644 index 00000000..9d2cc396 --- /dev/null +++ b/tests/test_stanza_xep_0422.py @@ -0,0 +1,33 @@ +import unittest +from slixmpp import Message +from slixmpp.test import SlixTest +from slixmpp.xmlstream import ET +from slixmpp.plugins.xep_0422 import stanza + + +class TestFastening(SlixTest): + + def setUp(self): + stanza.register_plugins() + + def testFastenExternal(self): + message = Message() + message['apply_to']['id'] = 'some-id' + message['apply_to'].xml.append( + ET.fromstring('Test') + ) + message['apply_to']['external']['name'] = 'body' + message['body'] = 'Toto' + + self.check(message, """ + + + Test + + + Toto + + """, use_values=False) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestFastening) diff --git a/tests/test_stanza_xep_0424.py b/tests/test_stanza_xep_0424.py new file mode 100644 index 00000000..c94ed79b --- /dev/null +++ b/tests/test_stanza_xep_0424.py @@ -0,0 +1,39 @@ +import unittest +from slixmpp import Message +from slixmpp.test import SlixTest +from slixmpp.plugins.xep_0424 import stanza + + +class TestRetraction(SlixTest): + + def setUp(self): + stanza.register_plugins() + + def testRetract(self): + message = Message() + message['apply_to']['id'] = 'some-id' + message['apply_to']['retract'] + + self.check(message, """ + + + + + + """, use_values=False) + + def testRetracted(self): + message = Message() + message['retracted']['stamp'] = '2019-09-20T23:09:32Z' + message['retracted']['origin_id']['id'] = 'originid' + + self.check(message, """ + + + + + + """) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestRetraction) diff --git a/tests/test_stanza_xep_0425.py b/tests/test_stanza_xep_0425.py new file mode 100644 index 00000000..96d979e8 --- /dev/null +++ b/tests/test_stanza_xep_0425.py @@ -0,0 +1,47 @@ +import unittest +from slixmpp import Message, Iq, JID +from slixmpp.test import SlixTest +from slixmpp.plugins.xep_0425 import stanza + + +class TestModeration(SlixTest): + + def setUp(self): + stanza.register_plugins() + + def testModerate(self): + iq = Iq() + iq['type'] = 'set' + iq['id'] = 'a' + iq['apply_to']['id'] = 'some-id' + iq['apply_to']['moderate'].enable('retract') + iq['apply_to']['moderate']['reason'] = 'R' + + self.check(iq, """ + + + + + R + + + + """, use_values=False) + + def testModerated(self): + message = Message() + message['moderated']['by'] = JID('toto@titi') + message['moderated']['retracted']['stamp'] = '2019-09-20T23:09:32Z' + message['moderated']['reason'] = 'R' + + self.check(message, """ + + + + R + + + """) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestModeration) diff --git a/tests/test_stanza_xep_0439.py b/tests/test_stanza_xep_0439.py new file mode 100644 index 00000000..fbd3aa47 --- /dev/null +++ b/tests/test_stanza_xep_0439.py @@ -0,0 +1,57 @@ +import unittest +from slixmpp import Message +from slixmpp.test import SlixTest +from slixmpp.plugins.xep_0439 import stanza + + +class TestQuickResponse(SlixTest): + + def setUp(self): + stanza.register_plugins() + + def testResponse(self): + message = Message() + message['body'] = 'Reply 1 or 2?' + for (value, label) in [('1', 'Rep 1'), ('2', 'Rep 2')]: + rep = stanza.Response() + rep['value'] = value + rep['label'] = label + message.append(rep) + + self.check(message, """ + + Reply 1 or 2? + + + + """, use_values=False) + + def testAction(self): + message = Message() + message['body'] = 'action 1 or 2?' + for (id_, label) in [('1', 'action 1'), ('2', 'action 2')]: + act = stanza.Action() + act['id'] = id_ + act['label'] = label + message.append(act) + + self.check(message, """ + + action 1 or 2? + + + + """, use_values=False) + + def testActionSelected(self): + message = Message() + message['action_selected']['id'] = 'act1' + + self.check(message, """ + + + + """, use_values=False) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestQuickResponse) -- cgit v1.2.3