From fac3bca1f6fd2412b52c3e7ce9b0971d8a290083 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 19 Aug 2010 19:11:12 -0400 Subject: Updated ElementBase.__delitem__ and added unit tests. --- tests/test_elementbase.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 95502f54..bf86e599 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -189,5 +189,46 @@ class TestElementBase(SleekTest): """) + 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, """ + + a + + + """) + + del stanza['bar'] + del stanza['baz'] + del stanza['qux'] + del stanza['foobar'] + + self.checkStanza(TestStanza, stanza, """ + + """) suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) -- cgit v1.2.3 From 8a0616b3e0c9b5b79ce9418a2494303b28863b4b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 19 Aug 2010 20:41:26 -0400 Subject: Updated ElementBase methods _getAttr, _setAttr, and _delAttr with docs and tests. --- tests/test_elementbase.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index bf86e599..78277af4 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -231,4 +231,41 @@ class TestElementBase(SleekTest): """) + 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, """ + + """) + + 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, """ + + """) + + self.failUnless(stanza._getAttr('bar') == 'a', + "Retrieved XML attribute value is incorrect.") + + stanza._setAttr('bar', None) + stanza._delAttr('baz') + + self.checkStanza(TestStanza, stanza, """ + + """) + + self.failUnless(stanza._getAttr('bar', 'c') == 'c', + "Incorrect default value returned for an unset XML attribute.") + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) -- cgit v1.2.3