From 2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 13 Aug 2010 21:33:11 -0400 Subject: Updated ElementBase.__getitem__ with docs and unit tests. --- tests/test_elementbase.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 99c397a5..d6fd457c 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -109,5 +109,46 @@ class TestElementBase(SleekTest): """) + def testGetItem(self): + """Test accessing stanza interfaces.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz')) + sub_interfaces = set(('baz',)) + + class TestStanzaPlugin(ElementBase): + name = "foobar" + namespace = "foo" + plugin_attrib = "foobar" + interfaces = set(('fizz',)) + + TestStanza.subitem = (TestStanza,) + registerStanzaPlugin(TestStanza, TestStanzaPlugin) + + stanza = TestStanza() + substanza = TestStanza() + stanza.append(substanza) + stanza.setStanzaValues({'bar': 'a', + 'baz': 'b', + 'foobar': {'fizz': 'c'}}) + + # Test non-plugin interfaces + expected = {'substanzas': [substanza], + 'bar': 'a', + 'baz': 'b', + 'meh': ''} + for interface, value in expected.items(): + result = stanza[interface] + self.failUnless(result == value, + "Incorrect stanza interface access result: %s" % result) + + # Test plugin interfaces + self.failUnless(isinstance(stanza['foobar'], TestStanzaPlugin), + "Incorrect plugin object result.") + self.failUnless(stanza['foobar']['fizz'] == 'c', + "Incorrect plugin subvalue result.") + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) -- cgit v1.2.3