summaryrefslogtreecommitdiff
path: root/tests/test_elementbase.py
diff options
context:
space:
mode:
authorLance Stout <lstout@kestrel.cs.clemson.edu>2010-08-24 09:37:42 -0400
committerLance Stout <lstout@kestrel.cs.clemson.edu>2010-08-24 09:37:42 -0400
commitc8f406d1b3e53aafdf549c93f3eeb44910c7f580 (patch)
tree25cdb85b3152a532595ef57d5c834fa80e9bb4b2 /tests/test_elementbase.py
parent203986dd7c485aa012fd5d84e58165374031ce87 (diff)
downloadslixmpp-c8f406d1b3e53aafdf549c93f3eeb44910c7f580.tar.gz
slixmpp-c8f406d1b3e53aafdf549c93f3eeb44910c7f580.tar.bz2
slixmpp-c8f406d1b3e53aafdf549c93f3eeb44910c7f580.tar.xz
slixmpp-c8f406d1b3e53aafdf549c93f3eeb44910c7f580.zip
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.
Diffstat (limited to 'tests/test_elementbase.py')
-rw-r--r--tests/test_elementbase.py51
1 files changed, 51 insertions, 0 deletions
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, """
+ <foo xmlns="foo">
+ <wrapper>
+ <bar>a</bar>
+ <baz>b</baz>
+ </wrapper>
+ </foo>
+ """)
+ stanza._setSubText('bar', text='', keep=True)
+ self.checkStanza(TestStanza, stanza, """
+ <foo xmlns="foo">
+ <wrapper>
+ <bar />
+ <baz>b</baz>
+ </wrapper>
+ </foo>
+ """, use_values=False)
+
+ stanza['bar'] = 'a'
+ stanza._setSubText('bar', text='')
+ self.checkStanza(TestStanza, stanza, """
+ <foo xmlns="foo">
+ <wrapper>
+ <baz>b</baz>
+ </wrapper>
+ </foo>
+ """)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase)