diff options
author | Lance Stout <lancestout@gmail.com> | 2011-03-24 13:15:00 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-03-24 13:15:00 -0400 |
commit | 77601f7262370ba172966352a94575ec02b4a776 (patch) | |
tree | 94d4db4e2718d6c919c3fbd6ad0bd4f5f1e53566 /tests | |
parent | d9be51b2efcdaaf6b62488700eb3ce859bb0958a (diff) | |
parent | d94811d81d68d948155d42ff9096c23ccb90a73c (diff) | |
download | slixmpp-77601f7262370ba172966352a94575ec02b4a776.tar.gz slixmpp-77601f7262370ba172966352a94575ec02b4a776.tar.bz2 slixmpp-77601f7262370ba172966352a94575ec02b4a776.tar.xz slixmpp-77601f7262370ba172966352a94575ec02b4a776.zip |
Merge branch 'develop' into roster
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_stanza_element.py | 97 | ||||
-rw-r--r-- | tests/test_stream_exceptions.py | 8 |
2 files changed, 94 insertions, 11 deletions
diff --git a/tests/test_stanza_element.py b/tests/test_stanza_element.py index f7387d36..dc67d1c5 100644 --- a/tests/test_stanza_element.py +++ b/tests/test_stanza_element.py @@ -53,9 +53,8 @@ class TestElementBase(SleekTest): name = "foo" namespace = "foo" interfaces = set(('bar', 'baz')) - subitem = set((TestSubStanza,)) - register_stanza_plugin(TestStanza, TestStanzaPlugin) + register_stanza_plugin(TestStanza, TestStanzaPlugin, iterable=True) stanza = TestStanza() stanza['bar'] = 'a' @@ -100,8 +99,8 @@ class TestElementBase(SleekTest): name = "foo" namespace = "foo" interfaces = set(('bar', 'baz')) - subitem = set((TestSubStanza,)) + register_stanza_plugin(TestStanza, TestSubStanza, iterable=True) register_stanza_plugin(TestStanza, TestStanzaPlugin) register_stanza_plugin(TestStanza, TestStanzaPlugin2) @@ -115,7 +114,7 @@ class TestElementBase(SleekTest): 'substanzas': [{'__childtag__': '{foo}subfoo', 'bar': 'c', 'baz': ''}]} - stanza.setStanzaValues(values) + stanza.values = values self.check(stanza, """ <foo xmlns="foo" bar="a"> @@ -143,7 +142,7 @@ class TestElementBase(SleekTest): plugin_attrib = "foobar" interfaces = set(('fizz',)) - TestStanza.subitem = (TestStanza,) + register_stanza_plugin(TestStanza, TestStanza, iterable=True) register_stanza_plugin(TestStanza, TestStanzaPlugin) stanza = TestStanza() @@ -457,7 +456,6 @@ class TestElementBase(SleekTest): namespace = "foo" interfaces = set(('bar','baz', 'qux')) sub_interfaces = set(('qux',)) - subitem = (TestSubStanza,) def setQux(self, value): self._set_sub_text('qux', text=value) @@ -470,6 +468,7 @@ class TestElementBase(SleekTest): namespace = "http://test/slash/bar" interfaces = set(('attrib',)) + register_stanza_plugin(TestStanza, TestSubStanza, iterable=True) register_stanza_plugin(TestStanza, TestStanzaPlugin) stanza = TestStanza() @@ -590,7 +589,8 @@ class TestElementBase(SleekTest): name = "foo" namespace = "foo" interfaces = set(('bar', 'baz')) - subitem = (TestSubStanza,) + + register_stanza_plugin(TestStanza, TestSubStanza, iterable=True) stanza = TestStanza() substanza1 = TestSubStanza() @@ -657,4 +657,87 @@ class TestElementBase(SleekTest): self.failUnless(stanza1 != stanza2, "Divergent stanza copies incorrectly compared equal.") + def testExtension(self): + """Testing using is_extension.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz')) + + class TestExtension(ElementBase): + name = 'extended' + namespace = 'foo' + plugin_attrib = name + interfaces = set((name,)) + is_extension = True + + def set_extended(self, value): + self.xml.text = value + + def get_extended(self): + return self.xml.text + + def del_extended(self): + self.parent().xml.remove(self.xml) + + register_stanza_plugin(TestStanza, TestExtension) + + stanza = TestStanza() + stanza['extended'] = 'testing' + + self.check(stanza, """ + <foo xmlns="foo"> + <extended>testing</extended> + </foo> + """) + + self.failUnless(stanza['extended'] == 'testing', + "Could not retrieve stanza extension value.") + + del stanza['extended'] + self.check(stanza, """ + <foo xmlns="foo" /> + """) + + def testOverrides(self): + """Test using interface overrides.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz')) + + class TestOverride(ElementBase): + name = 'overrider' + namespace = 'foo' + plugin_attrib = name + interfaces = set(('bar',)) + overrides = ['set_bar'] + + def setup(self, xml): + # Don't create XML for the plugin + self.xml = ET.Element('') + + def set_bar(self, value): + if not value.startswith('override-'): + self.parent()._set_attr('bar', 'override-%s' % value) + else: + self.parent()._set_attr('bar', value) + + stanza = TestStanza() + stanza['bar'] = 'foo' + self.check(stanza, """ + <foo xmlns="foo" bar="foo" /> + """) + + register_stanza_plugin(TestStanza, TestOverride, overrides=True) + + stanza = TestStanza() + stanza['bar'] = 'foo' + self.check(stanza, """ + <foo xmlns="foo" bar="override-foo" /> + """) + + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) diff --git a/tests/test_stream_exceptions.py b/tests/test_stream_exceptions.py index a4598a10..bc01c2a7 100644 --- a/tests/test_stream_exceptions.py +++ b/tests/test_stream_exceptions.py @@ -37,7 +37,7 @@ class TestStreamExceptions(SleekTest): self.send(""" <message type="error"> - <error type="cancel"> + <error type="cancel" code="501"> <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> @@ -73,7 +73,7 @@ class TestStreamExceptions(SleekTest): self.send(""" <iq type="error" id="0"> <query xmlns="test" /> - <error type="cancel"> + <error type="cancel" code="501"> <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> @@ -103,7 +103,7 @@ class TestStreamExceptions(SleekTest): self.send(""" <message type="error"> - <error type="cancel"> + <error type="cancel" code="501"> <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> @@ -137,7 +137,7 @@ class TestStreamExceptions(SleekTest): self.send(""" <message type="error"> - <error type="cancel"> + <error type="cancel" code="500"> <undefined-condition xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> |