From 37ff17b0cbefd8a0056b131621728123b292e211 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 26 Aug 2010 18:27:18 -0400 Subject: Added unit test for _fix_ns for handling namespaces with forward slashes. --- tests/test_elementbase.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/test_elementbase.py') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 6b0c076b..8de7a169 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -3,6 +3,21 @@ from sleekxmpp.xmlstream.stanzabase import ElementBase class TestElementBase(SleekTest): + def testFixNs(self): + """Test fixing namespaces in an XPath expression.""" + + e = ElementBase() + ns = "http://jabber.org/protocol/disco#items" + result = e._fix_ns("{%s}foo/bar/{abc}baz/{%s}more" % (ns, ns)) + + expected = "/".join(["{%s}foo" % ns, + "{%s}bar" % ns, + "{abc}baz", + "{%s}more" % ns]) + self.failUnless(expected == result, + "Incorrect namespace fixing result: %s" % str(result)) + + def testExtendedName(self): """Test element names of the form tag1/tag2/tag3.""" -- cgit v1.2.3 From 906aa0bd6896d119bcbabc6e21de31c2171316b9 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 27 Aug 2010 15:48:48 -0400 Subject: Fixed SleekTest compare method to check XML text. Corrected resulting test failures. All pass again. --- tests/test_elementbase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_elementbase.py') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 8de7a169..b6d7c6f0 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -347,7 +347,7 @@ class TestElementBase(SleekTest): """) - stanza._setSubText('bar', text='', keep=True) + stanza._setSubText('wrapper/bar', text='', keep=True) self.checkStanza(TestStanza, stanza, """ @@ -358,7 +358,7 @@ class TestElementBase(SleekTest): """, use_values=False) stanza['bar'] = 'a' - stanza._setSubText('bar', text='') + stanza._setSubText('wrapper/bar', text='') self.checkStanza(TestStanza, stanza, """ -- cgit v1.2.3 From 9c62bce2060e30e41c3710587f6bd9992625b245 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 30 Aug 2010 14:55:30 -0400 Subject: Updated ElementBase.match to respect namespaces with slashes. Required adding option to _fix_ns to not propagate namespaces to child elements. --- tests/test_elementbase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_elementbase.py') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index b6d7c6f0..8898b3fc 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -459,7 +459,7 @@ class TestElementBase(SleekTest): class TestStanzaPlugin(ElementBase): name = "plugin" - namespace = "bar" + namespace = "http://test/slash/bar" interfaces = set(('attrib',)) registerStanzaPlugin(TestStanza, TestStanzaPlugin) @@ -483,7 +483,7 @@ class TestElementBase(SleekTest): self.failUnless(stanza.match("foo/plugin@attrib=c"), "Stanza did not match with plugin and attribute.") - self.failUnless(stanza.match("foo/{bar}plugin"), + self.failUnless(stanza.match("foo/{http://test/slash/bar}plugin"), "Stanza did not match with namespaced plugin.") substanza = TestSubStanza() -- cgit v1.2.3 From 3749c1b88c4774b85fcee1e26e8bce8dbeef23c7 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 30 Aug 2010 17:12:10 -0400 Subject: Fixed ElementBase.match to match using sub_interface elements. --- tests/test_elementbase.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests/test_elementbase.py') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 8898b3fc..dfd37b53 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -454,9 +454,16 @@ class TestElementBase(SleekTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar','baz')) + interfaces = set(('bar','baz', 'qux')) + sub_interfaces = set(('qux',)) subitem = (TestSubStanza,) + def setQux(self, value): + self._setSubText('qux', text=value) + + def getQux(self): + return self._getSubText('qux') + class TestStanzaPlugin(ElementBase): name = "plugin" namespace = "http://test/slash/bar" @@ -479,6 +486,17 @@ class TestElementBase(SleekTest): self.failUnless(stanza.match("foo@bar=a@baz=b"), "Stanza did not match its own name with multiple attributes.") + stanza['qux'] = 'c' + self.failUnless(stanza.match("foo/qux"), + "Stanza did not match with subelements.") + + stanza['qux'] = '' + self.failUnless(stanza.match("foo/qux") == False, + "Stanza matched missing subinterface element.") + + self.failUnless(stanza.match("foo/bar") == False, + "Stanza matched nonexistent element.") + stanza['plugin']['attrib'] = 'c' self.failUnless(stanza.match("foo/plugin@attrib=c"), "Stanza did not match with plugin and attribute.") -- cgit v1.2.3