summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lstout@kestrel.cs.clemson.edu>2010-08-24 08:55:37 -0400
committerLance Stout <lstout@kestrel.cs.clemson.edu>2010-08-24 08:55:37 -0400
commit203986dd7c485aa012fd5d84e58165374031ce87 (patch)
tree8e149e61cefd11b76c9c5e2eeddfb998b1db76b6 /tests
parentf4ecf0bac4089771a20ea6117f0a505c0b0b6e37 (diff)
downloadslixmpp-203986dd7c485aa012fd5d84e58165374031ce87.tar.gz
slixmpp-203986dd7c485aa012fd5d84e58165374031ce87.tar.bz2
slixmpp-203986dd7c485aa012fd5d84e58165374031ce87.tar.xz
slixmpp-203986dd7c485aa012fd5d84e58165374031ce87.zip
Updated ElementBase._getSubText and added unit tests.
Also added ElementBase._fix_ns() to apply the stanza namespace to elements that don't have a namespace.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_elementbase.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py
index 78277af4..78cf47d6 100644
--- a/tests/test_elementbase.py
+++ b/tests/test_elementbase.py
@@ -267,5 +267,39 @@ class TestElementBase(SleekTest):
self.failUnless(stanza._getAttr('bar', 'c') == 'c',
"Incorrect default value returned for an unset XML attribute.")
+
+ def testGetSubText(self):
+ """Test retrieving the contents of a sub element."""
+
+ class TestStanza(ElementBase):
+ name = "foo"
+ namespace = "foo"
+ interfaces = set(('bar',))
+
+ def setBar(self, value):
+ wrapper = ET.Element("{foo}wrapper")
+ bar = ET.Element("{foo}bar")
+ bar.text = value
+ wrapper.append(bar)
+ self.xml.append(wrapper)
+
+ def getBar(self):
+ return self._getSubText("wrapper/bar", default="not found")
+
+ stanza = TestStanza()
+ self.failUnless(stanza['bar'] == 'not found',
+ "Default _getSubText value incorrect.")
+
+ stanza['bar'] = 'found'
+ self.checkStanza(TestStanza, stanza, """
+ <foo xmlns="foo">
+ <wrapper>
+ <bar>found</bar>
+ </wrapper>
+ </foo>
+ """)
+ self.failUnless(stanza['bar'] == 'found',
+ "_getSubText value incorrect: %s." % stanza['bar'])
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase)