diff options
author | Lance Stout <lancestout@gmail.com> | 2010-08-25 14:40:16 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-08-25 14:40:16 -0400 |
commit | 1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30 (patch) | |
tree | 115d2d434592e10f08655a3693cc006820e6abef /tests/test_elementbase.py | |
parent | 5d458bf6c2fae32d659b29ac2697a20b781bfbd0 (diff) | |
download | slixmpp-1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30.tar.gz slixmpp-1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30.tar.bz2 slixmpp-1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30.tar.xz slixmpp-1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30.zip |
Updated ElementBase.match and added unit tests.
Diffstat (limited to 'tests/test_elementbase.py')
-rw-r--r-- | tests/test_elementbase.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 9628ea6c..d749f08e 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -428,5 +428,48 @@ class TestElementBase(SleekTest): </foo> """) + def testMatch(self): + """Test matching a stanza against an XPath expression.""" + + class TestSubStanza(ElementBase): + name = "sub" + namespace = "foo" + interfaces = set(('attrib',)) + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar','baz')) + subitem = (TestSubStanza,) + + class TestStanzaPlugin(ElementBase): + name = "plugin" + namespace = "foo" + interfaces = set(('attrib',)) + + registerStanzaPlugin(TestStanza, TestStanzaPlugin) + + stanza = TestStanza() + self.failUnless(stanza.match("foo"), + "Stanza did not match its own tag name.") + + stanza['bar'] = 'a' + self.failUnless(stanza.match("foo@bar=a"), + "Stanza did not match its own name with attribute value check.") + + stanza['baz'] = 'b' + self.failUnless(stanza.match("foo@bar=a@baz=b"), + "Stanza did not match its own name with multiple attributes.") + + stanza['plugin']['attrib'] = 'c' + self.failUnless(stanza.match("foo/plugin@attrib=c"), + "Stanza did not match with plugin and attribute.") + + substanza = TestSubStanza() + substanza['attrib'] = 'd' + stanza.append(substanza) + self.failUnless(stanza.match("foo/sub@attrib=d"), + "Stanza did not match with substanzas and attribute.") + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) |