diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_plugins.py | 8 | ||||
-rw-r--r-- | tests/test_stanza_element.py | 90 | ||||
-rw-r--r-- | tests/test_stanza_xep_0030.py | 18 | ||||
-rw-r--r-- | tests/test_stanza_xep_0050.py | 2 | ||||
-rw-r--r-- | tests/test_stanza_xep_0300.py | 57 | ||||
-rw-r--r-- | tests/test_stanza_xep_0380.py | 37 | ||||
-rw-r--r-- | tests/test_stream_presence.py | 8 | ||||
-rw-r--r-- | tests/test_stream_xep_0030.py | 8 | ||||
-rw-r--r-- | tests/test_stream_xep_0047.py | 2 | ||||
-rw-r--r-- | tests/test_stream_xep_0050.py | 2 |
10 files changed, 163 insertions, 69 deletions
diff --git a/tests/test_plugins.py b/tests/test_plugins.py index ee6d44c0..a8cc2744 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -14,21 +14,21 @@ class B(BasePlugin): class C(BasePlugin): name = 'c' - dependencies = set(['b', 'd']) + dependencies = {'b', 'd'} class D(BasePlugin): name = 'd' - dependencies = set(['c']) + dependencies = {'c'} class E(BasePlugin): name = 'e' - dependencies = set(['a', 'd']) + dependencies = {'a', 'd'} class F(BasePlugin): name = 'f' - dependencies = set(['a', 'b']) + dependencies = {'a', 'b'} register_plugin(A) diff --git a/tests/test_stanza_element.py b/tests/test_stanza_element.py index 240203cc..89ea0310 100644 --- a/tests/test_stanza_element.py +++ b/tests/test_stanza_element.py @@ -43,18 +43,18 @@ class TestElementBase(SlixTest): class TestStanzaPlugin(ElementBase): name = "foo2" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} plugin_attrib = "foo2" class TestSubStanza(ElementBase): name = "subfoo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} register_stanza_plugin(TestStanza, TestStanzaPlugin, iterable=True) @@ -90,24 +90,24 @@ class TestElementBase(SlixTest): class TestStanzaPlugin(ElementBase): name = "pluginfoo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} plugin_attrib = "plugin_foo" class TestStanzaPlugin2(ElementBase): name = "pluginfoo2" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} plugin_attrib = "plugin_foo2" class TestSubStanza(ElementBase): name = "subfoo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} register_stanza_plugin(TestStanza, TestSubStanza, iterable=True) register_stanza_plugin(TestStanza, TestStanzaPlugin) @@ -139,8 +139,8 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz', 'qux')) - sub_interfaces = set(('baz',)) + interfaces = {'bar', 'baz', 'qux'} + sub_interfaces = {'baz'} def get_qux(self): return 'qux' @@ -149,7 +149,7 @@ class TestElementBase(SlixTest): name = "foobar" namespace = "foo" plugin_attrib = "foobar" - interfaces = set(('fizz',)) + interfaces = {'fizz'} register_stanza_plugin(TestStanza, TestStanza, iterable=True) register_stanza_plugin(TestStanza, TestStanzaPlugin) @@ -185,8 +185,8 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz', 'qux')) - sub_interfaces = set(('baz',)) + interfaces = {'bar', 'baz', 'qux'} + sub_interfaces = {'baz'} def set_qux(self, value): pass @@ -195,7 +195,7 @@ class TestElementBase(SlixTest): name = "foobar" namespace = "foo" plugin_attrib = "foobar" - interfaces = set(('foobar',)) + interfaces = {'foobar'} register_stanza_plugin(TestStanza, TestStanzaPlugin) @@ -219,8 +219,8 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz', 'qux')) - sub_interfaces = set(('bar',)) + interfaces = {'bar', 'baz', 'qux'} + sub_interfaces = {'bar'} def del_qux(self): pass @@ -229,7 +229,7 @@ class TestElementBase(SlixTest): name = "foobar" namespace = "foo" plugin_attrib = "foobar" - interfaces = set(('foobar',)) + interfaces = {'foobar'} register_stanza_plugin(TestStanza, TestStanzaPlugin) @@ -261,7 +261,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} stanza = TestStanza() @@ -298,7 +298,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar',)) + interfaces = {'bar'} def set_bar(self, value): wrapper = ET.Element("{foo}wrapper") @@ -331,7 +331,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} def set_baz(self, value): self._set_sub_text("wrapper/baz", text=value) @@ -382,7 +382,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} def set_bar(self, value): self._set_sub_text("path/to/only/bar", value) @@ -458,13 +458,13 @@ class TestElementBase(SlixTest): class TestSubStanza(ElementBase): name = "sub" namespace = "baz" - interfaces = set(('attrib',)) + interfaces = {'attrib'} class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar','baz', 'qux')) - sub_interfaces = set(('qux',)) + interfaces = {'bar','baz', 'qux'} + sub_interfaces = {'qux'} def set_qux(self, value): self._set_sub_text('qux', text=value) @@ -475,7 +475,7 @@ class TestElementBase(SlixTest): class TestStanzaPlugin(ElementBase): name = "plugin" namespace = "http://test/slash/bar" - interfaces = set(('attrib',)) + interfaces = {'attrib'} register_stanza_plugin(TestStanza, TestSubStanza, iterable=True) register_stanza_plugin(TestStanza, TestStanzaPlugin) @@ -528,7 +528,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} stanza1 = TestStanza() stanza1['bar'] = 'a' @@ -554,19 +554,19 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} plugin_attrib = 'qux' register_stanza_plugin(TestStanza, TestStanza) stanza = TestStanza() - self.failUnless(set(stanza.keys()) == set(('lang', 'bar', 'baz')), + self.failUnless(set(stanza.keys()) == {'lang', 'bar', 'baz'}, "Returned set of interface keys does not match expected.") stanza.enable('qux') - self.failUnless(set(stanza.keys()) == set(('lang', 'bar', 'baz', 'qux')), + self.failUnless(set(stanza.keys()) == {'lang', 'bar', 'baz', 'qux'}, "Incorrect set of interface and plugin keys.") def testGet(self): @@ -575,7 +575,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} stanza = TestStanza() stanza['bar'] = 'a' @@ -592,12 +592,12 @@ class TestElementBase(SlixTest): class TestSubStanza(ElementBase): name = "foobar" namespace = "foo" - interfaces = set(('qux',)) + interfaces = {'qux'} class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} register_stanza_plugin(TestStanza, TestSubStanza, iterable=True) @@ -652,7 +652,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} stanza1 = TestStanza() stanza1['bar'] = 'a' @@ -672,13 +672,13 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} class TestExtension(ElementBase): name = 'extended' namespace = 'foo' plugin_attrib = name - interfaces = set((name,)) + interfaces = {name} is_extension = True def set_extended(self, value): @@ -715,13 +715,13 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = {'bar', 'baz'} class TestOverride(ElementBase): name = 'overrider' namespace = 'foo' plugin_attrib = name - interfaces = set(('bar',)) + interfaces = {'bar'} overrides = ['set_bar'] def setup(self, xml): @@ -754,7 +754,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(['bar']) + interfaces = {'bar'} bool_interfaces = interfaces stanza = TestStanza() @@ -946,7 +946,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -972,7 +972,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -1008,7 +1008,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -1040,7 +1040,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -1096,7 +1096,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -1136,7 +1136,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -1177,7 +1177,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces @@ -1217,7 +1217,7 @@ class TestElementBase(SlixTest): class TestStanza(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['test']) + interfaces = {'test'} sub_interfaces = interfaces lang_interfaces = interfaces diff --git a/tests/test_stanza_xep_0030.py b/tests/test_stanza_xep_0030.py index d8e99ffb..d85f1980 100644 --- a/tests/test_stanza_xep_0030.py +++ b/tests/test_stanza_xep_0030.py @@ -254,10 +254,10 @@ class TestDisco(SlixTest): iq['disco_info'].add_identity('client', 'pc', lang='en') iq['disco_info'].add_identity('client', 'pc', lang='fr') - expected = set([('client', 'pc', None, None), - ('client', 'pc', 'no', None), - ('client', 'pc', 'en', None), - ('client', 'pc', 'fr', None)]) + expected = {('client', 'pc', None, None), + ('client', 'pc', 'no', None), + ('client', 'pc', 'en', None), + ('client', 'pc', 'fr', None)} self.failUnless(iq['disco_info']['identities'] == expected, "Identities do not match:\n%s\n%s" % ( expected, @@ -274,7 +274,7 @@ class TestDisco(SlixTest): iq['disco_info'].add_identity('client', 'pc', lang='en') iq['disco_info'].add_identity('client', 'pc', lang='fr') - expected = set([('client', 'pc', 'no', None)]) + expected = {('client', 'pc', 'no', None)} result = iq['disco_info'].get_identities(lang='no') self.failUnless(result == expected, "Identities do not match:\n%s\n%s" % ( @@ -336,7 +336,7 @@ class TestDisco(SlixTest): iq['disco_info'].add_feature('bar') iq['disco_info'].add_feature('baz') - expected = set(['foo', 'bar', 'baz']) + expected = {'foo', 'bar', 'baz'} self.failUnless(iq['disco_info']['features'] == expected, "Features do not match:\n%s\n%s" % ( expected, @@ -472,9 +472,9 @@ class TestDisco(SlixTest): node='bar', name='Tester') - expected = set([('user@localhost', None, None), - ('user@localhost', 'foo', None), - ('test@localhost', 'bar', 'Tester')]) + expected = {('user@localhost', None, None), + ('user@localhost', 'foo', None), + ('test@localhost', 'bar', 'Tester')} self.failUnless(iq['disco_items']['items'] == expected, "Items do not match:\n%s\n%s" % ( expected, diff --git a/tests/test_stanza_xep_0050.py b/tests/test_stanza_xep_0050.py index 7272d783..0898b136 100644 --- a/tests/test_stanza_xep_0050.py +++ b/tests/test_stanza_xep_0050.py @@ -51,7 +51,7 @@ class TestAdHocCommandStanzas(SlixTest): iq['command']['actions'] = ['prev', 'next'] results = iq['command']['actions'] - expected = set(['prev', 'next']) + expected = {'prev', 'next'} self.assertEqual(results, expected, "Incorrect next actions: %s" % results) diff --git a/tests/test_stanza_xep_0300.py b/tests/test_stanza_xep_0300.py new file mode 100644 index 00000000..5ffd8e3b --- /dev/null +++ b/tests/test_stanza_xep_0300.py @@ -0,0 +1,57 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2017 Emmanuel Gil Peyrot + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" + +import unittest +from slixmpp import Iq +from slixmpp.test import SlixTest +from slixmpp.plugins.xep_0300 import Hash +from slixmpp.xmlstream import register_stanza_plugin + + +class TestHash(SlixTest): + + def setUp(self): + register_stanza_plugin(Iq, Hash) + + def testSimpleElement(self): + """Test that the element is created correctly.""" + iq = Iq() + iq['type'] = 'set' + iq['hash']['algo'] = 'sha-256' + iq['hash']['value'] = 'EQgS9n+h4fARf289cCQcGkKnsHcRqTwkd8xRbZBC+ds=' + + self.check(iq, """ + <iq type="set"> + <hash xmlns="urn:xmpp:hashes:2" algo="sha-256">EQgS9n+h4fARf289cCQcGkKnsHcRqTwkd8xRbZBC+ds=</hash> + </iq> + """) + + def testInvalidAlgo(self): + """Test that invalid algos raise an exception.""" + iq = Iq() + iq['type'] = 'set' + try: + iq['hash']['algo'] = 'coucou' + except ValueError: + pass + else: + raise self.failureException + + #def testDisabledAlgo(self): + # """Test that disabled algos aren’t used.""" + # iq = Iq() + # iq['type'] = 'set' + # try: + # iq['hash']['algo'] = 'sha-1' + # except ValueError: + # pass + # else: + # raise self.failureException + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestHash) diff --git a/tests/test_stanza_xep_0380.py b/tests/test_stanza_xep_0380.py new file mode 100644 index 00000000..9ed349bf --- /dev/null +++ b/tests/test_stanza_xep_0380.py @@ -0,0 +1,37 @@ +import unittest +from slixmpp import Message +from slixmpp.test import SlixTest +import slixmpp.plugins.xep_0380 as xep_0380 +from slixmpp.xmlstream import register_stanza_plugin + + +class TestEME(SlixTest): + + def setUp(self): + register_stanza_plugin(Message, xep_0380.stanza.Encryption) + + def testCreateEME(self): + """Testing creating EME.""" + + xmlstring = """ + <message> + <encryption xmlns="urn:xmpp:eme:0" namespace="%s"%s /> + </message> + """ + + msg = self.Message() + self.check(msg, "<message />") + + msg['eme']['namespace'] = 'urn:xmpp:otr:0' + self.check(msg, xmlstring % ('urn:xmpp:otr:0', '')) + + msg['eme']['namespace'] = 'urn:xmpp:openpgp:0' + self.check(msg, xmlstring % ('urn:xmpp:openpgp:0', '')) + + msg['eme']['name'] = 'OX' + self.check(msg, xmlstring % ('urn:xmpp:openpgp:0', ' name="OX"')) + + del msg['eme'] + self.check(msg, "<message />") + +suite = unittest.TestLoader().loadTestsFromTestCase(TestEME) diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py index ea2337a2..caf3fef9 100644 --- a/tests/test_stream_presence.py +++ b/tests/test_stream_presence.py @@ -38,7 +38,7 @@ class TestStreamPresence(SlixTest): to="tester@localhost"/> """) - self.assertEqual(events, set(('unavailable',)), + self.assertEqual(events, {'unavailable'}, "Got offline incorrectly triggered: %s." % events) def testGotOffline(self): @@ -102,7 +102,7 @@ class TestStreamPresence(SlixTest): to="tester@localhost" /> """) - expected = set(('presence_available', 'got_online')) + expected = {'presence_available', 'got_online'} self.assertEqual(events, expected, "Incorrect events triggered: %s" % events) @@ -151,7 +151,7 @@ class TestStreamPresence(SlixTest): type="subscribe" /> """) - expected = set(('presence_subscribe', 'changed_subscription')) + expected = {'presence_subscribe', 'changed_subscription'} self.assertEqual(events, expected, "Incorrect events triggered: %s" % events) @@ -185,7 +185,7 @@ class TestStreamPresence(SlixTest): type="unsubscribed" /> """) - expected = set(('presence_subscribe', 'changed_subscription')) + expected = {'presence_subscribe', 'changed_subscription'} self.assertEqual(events, expected, "Incorrect events triggered: %s" % events) diff --git a/tests/test_stream_xep_0030.py b/tests/test_stream_xep_0030.py index 1d6337d5..d1ad9087 100644 --- a/tests/test_stream_xep_0030.py +++ b/tests/test_stream_xep_0030.py @@ -307,7 +307,7 @@ class TestStreamDisco(SlixTest): </iq> """) - self.assertEqual(events, set(('disco_info',)), + self.assertEqual(events, {'disco_info'}, "Disco info event was not triggered: %s" % events) def testDynamicItemsJID(self): @@ -502,9 +502,9 @@ class TestStreamDisco(SlixTest): </iq> """) - items = set([('user@localhost', 'bar', 'Test'), - ('user@localhost', 'baz', 'Test 2')]) - self.assertEqual(events, set(('disco_items',)), + items = {('user@localhost', 'bar', 'Test'), + ('user@localhost', 'baz', 'Test 2')} + self.assertEqual(events, {'disco_items'}, "Disco items event was not triggered: %s" % events) self.assertEqual(results, items, "Unexpected items: %s" % results) diff --git a/tests/test_stream_xep_0047.py b/tests/test_stream_xep_0047.py index ecba2445..a0e6c227 100644 --- a/tests/test_stream_xep_0047.py +++ b/tests/test_stream_xep_0047.py @@ -77,7 +77,7 @@ class TestInBandByteStreams(SlixTest): from="tester@localhost/receiver" /> """) - self.assertEqual(events, set(['ibb_stream_start', 'callback'])) + self.assertEqual(events, {'ibb_stream_start', 'callback'}) @asyncio.coroutine def testSendData(self): diff --git a/tests/test_stream_xep_0050.py b/tests/test_stream_xep_0050.py index 65b5f678..d1a94ecc 100644 --- a/tests/test_stream_xep_0050.py +++ b/tests/test_stream_xep_0050.py @@ -25,7 +25,7 @@ class TestAdHocCommands(SlixTest): class TestPayload(ElementBase): name = 'foo' namespace = 'test' - interfaces = set(['bar']) + interfaces = {'bar'} plugin_attrib = name Command = self.xmpp['xep_0050'].stanza.Command |