From 1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 25 Aug 2010 14:40:16 -0400 Subject: Updated ElementBase.match and added unit tests. --- tests/test_elementbase.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests') 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): """) + 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) -- cgit v1.2.3