summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-08-13 21:33:11 -0400
committerLance Stout <lancestout@gmail.com>2010-08-13 21:33:11 -0400
commit2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8 (patch)
tree3b030aa796b6def1aa39ae0f5dc18ffd75d15b14 /tests
parentfe49b8c377b8491ec5fd5bc74d44834bd384f6a8 (diff)
downloadslixmpp-2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8.tar.gz
slixmpp-2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8.tar.bz2
slixmpp-2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8.tar.xz
slixmpp-2f6f4fc16d81fd01bc5a4569e0a1bc4ede4a3af8.zip
Updated ElementBase.__getitem__ with docs and unit tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_elementbase.py41
1 files changed, 41 insertions, 0 deletions
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):
</foo>
""")
+ 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)