From c8f406d1b3e53aafdf549c93f3eeb44910c7f580 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 24 Aug 2010 09:37:42 -0400 Subject: Updated ElementBase._setSubText and added unit tests. _setSubText can now handle elements specified by an XPath expression, and will build up the element tree as needed, reusing an existing elements in the path. --- tests/test_elementbase.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 78cf47d6..2b61489a 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -301,5 +301,56 @@ class TestElementBase(SleekTest): self.failUnless(stanza['bar'] == 'found', "_getSubText value incorrect: %s." % stanza['bar']) + def testSubElement(self): + """Test setting the contents of a sub element.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz')) + + def setBaz(self, value): + self._setSubText("wrapper/baz", text=value) + + def getBaz(self): + return self._getSubText("wrapper/baz") + + def setBar(self, value): + self._setSubText("wrapper/bar", text=value) + + def getBar(self): + return self._getSubText("wrapper/bar") + + stanza = TestStanza() + stanza['bar'] = 'a' + stanza['baz'] = 'b' + self.checkStanza(TestStanza, stanza, """ + + + a + b + + + """) + stanza._setSubText('bar', text='', keep=True) + self.checkStanza(TestStanza, stanza, """ + + + + b + + + """, use_values=False) + + stanza['bar'] = 'a' + stanza._setSubText('bar', text='') + self.checkStanza(TestStanza, stanza, """ + + + b + + + """) + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) -- cgit v1.2.3