diff options
author | Nathan Fritz <nathan@andyet.net> | 2010-08-19 19:54:09 -0700 |
---|---|---|
committer | Nathan Fritz <nathan@andyet.net> | 2010-08-19 19:54:09 -0700 |
commit | c05ddcb7f5eaa5bbf7efb4e765d04b62212a3394 (patch) | |
tree | 80fa80c10df03eb592eac5c68f736b63562e8de4 /tests | |
parent | eb9e72fe3e0b125698cf91c3512ec9ecf4646ad8 (diff) | |
parent | 8a0616b3e0c9b5b79ce9418a2494303b28863b4b (diff) | |
download | slixmpp-c05ddcb7f5eaa5bbf7efb4e765d04b62212a3394.tar.gz slixmpp-c05ddcb7f5eaa5bbf7efb4e765d04b62212a3394.tar.bz2 slixmpp-c05ddcb7f5eaa5bbf7efb4e765d04b62212a3394.tar.xz slixmpp-c05ddcb7f5eaa5bbf7efb4e765d04b62212a3394.zip |
Merge branch 'develop' of git@github.com:fritzy/SleekXMPP into develop
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_elementbase.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 95502f54..78277af4 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -189,5 +189,83 @@ class TestElementBase(SleekTest): </foo> """) + def testDelItem(self): + """Test deleting stanza interface values.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz', 'qux')) + sub_interfaces = set(('bar',)) + + def delQux(self): + pass + + class TestStanzaPlugin(ElementBase): + name = "foobar" + namespace = "foo" + plugin_attrib = "foobar" + interfaces = set(('foobar',)) + + registerStanzaPlugin(TestStanza, TestStanzaPlugin) + + stanza = TestStanza() + stanza['bar'] = 'a' + stanza['baz'] = 'b' + stanza['qux'] = 'c' + stanza['foobar']['foobar'] = 'd' + + self.checkStanza(TestStanza, stanza, """ + <foo xmlns="foo" baz="b" qux="c"> + <bar>a</bar> + <foobar foobar="d" /> + </foo> + """) + + del stanza['bar'] + del stanza['baz'] + del stanza['qux'] + del stanza['foobar'] + + self.checkStanza(TestStanza, stanza, """ + <foo xmlns="foo" qux="c" /> + """) + + def testModifyingAttributes(self): + """Test modifying top level attributes of a stanza's XML object.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz')) + + stanza = TestStanza() + + self.checkStanza(TestStanza, stanza, """ + <foo xmlns="foo" /> + """) + + self.failUnless(stanza._getAttr('bar') == '', + "Incorrect value returned for an unset XML attribute.") + + stanza._setAttr('bar', 'a') + stanza._setAttr('baz', 'b') + + self.checkStanza(TestStanza, stanza, """ + <foo xmlns="foo" bar="a" baz="b" /> + """) + + self.failUnless(stanza._getAttr('bar') == 'a', + "Retrieved XML attribute value is incorrect.") + + stanza._setAttr('bar', None) + stanza._delAttr('baz') + + self.checkStanza(TestStanza, stanza, """ + <foo xmlns="foo" /> + """) + + self.failUnless(stanza._getAttr('bar', 'c') == 'c', + "Incorrect default value returned for an unset XML attribute.") suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) |