diff options
author | Lance Stout <lancestout@gmail.com> | 2010-08-19 14:21:58 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-08-19 14:21:58 -0400 |
commit | e4240dd593207a5912de996c42451b3946f113b2 (patch) | |
tree | 5f7832829a3449eef226429f849fec78aae2144a /tests | |
parent | 2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8 (diff) | |
download | slixmpp-e4240dd593207a5912de996c42451b3946f113b2.tar.gz slixmpp-e4240dd593207a5912de996c42451b3946f113b2.tar.bz2 slixmpp-e4240dd593207a5912de996c42451b3946f113b2.tar.xz slixmpp-e4240dd593207a5912de996c42451b3946f113b2.zip |
Updated ElementBase.__setitem__ and added unit tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_elementbase.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index d6fd457c..95502f54 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -115,9 +115,12 @@ class TestElementBase(SleekTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar', 'baz')) + interfaces = set(('bar', 'baz', 'qux')) sub_interfaces = set(('baz',)) + def getQux(self): + return 'qux' + class TestStanzaPlugin(ElementBase): name = "foobar" namespace = "foo" @@ -132,12 +135,14 @@ class TestElementBase(SleekTest): stanza.append(substanza) stanza.setStanzaValues({'bar': 'a', 'baz': 'b', + 'qux': 42, 'foobar': {'fizz': 'c'}}) # Test non-plugin interfaces expected = {'substanzas': [substanza], 'bar': 'a', 'baz': 'b', + 'qux': 'qux', 'meh': ''} for interface, value in expected.items(): result = stanza[interface] @@ -150,5 +155,39 @@ class TestElementBase(SleekTest): self.failUnless(stanza['foobar']['fizz'] == 'c', "Incorrect plugin subvalue result.") + def testSetItem(self): + """Test assigning to stanza interfaces.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz', 'qux')) + sub_interfaces = set(('baz',)) + + def setQux(self, value): + pass + + class TestStanzaPlugin(ElementBase): + name = "foobar" + namespace = "foo" + plugin_attrib = "foobar" + interfaces = set(('foobar',)) + + registerStanzaPlugin(TestStanza, TestStanzaPlugin) + + stanza = TestStanza() + + stanza['bar'] = 'attribute!' + stanza['baz'] = 'element!' + stanza['qux'] = 'overridden' + stanza['foobar'] = 'plugin' + + self.checkStanza(TestStanza, stanza, """ + <foo xmlns="foo" bar="attribute!"> + <baz>element!</baz> + <foobar foobar="plugin" /> + </foo> + """) + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) |