summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-05-05 14:01:13 -0700
committerLance Stout <lancestout@gmail.com>2012-05-05 14:01:13 -0700
commit9e86a7b357afffdf5cb99cf4de76472f29f740e4 (patch)
tree0449035228e7438da7ca6da25949e18ab9aab6f6 /tests
parent6a32417957a290c29b3e833bebf69fbcd8d9a8d3 (diff)
downloadslixmpp-9e86a7b357afffdf5cb99cf4de76472f29f740e4.tar.gz
slixmpp-9e86a7b357afffdf5cb99cf4de76472f29f740e4.tar.bz2
slixmpp-9e86a7b357afffdf5cb99cf4de76472f29f740e4.tar.xz
slixmpp-9e86a7b357afffdf5cb99cf4de76472f29f740e4.zip
Tidy up and add tests for multi_attrib plugins.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stanza_element.py160
1 files changed, 160 insertions, 0 deletions
diff --git a/tests/test_stanza_element.py b/tests/test_stanza_element.py
index 60ccb7c9..09093003 100644
--- a/tests/test_stanza_element.py
+++ b/tests/test_stanza_element.py
@@ -774,5 +774,165 @@ class TestElementBase(SleekTest):
<foo xmlns="foo" />
""")
+ def testGetMultiAttrib(self):
+ """Test retrieving multi_attrib substanzas."""
+
+ class TestStanza(ElementBase):
+ name = 'foo'
+ namespace = 'foo'
+ interfaces = set()
+
+ class TestMultiStanza1(ElementBase):
+ name = 'bar'
+ namespace = 'bar'
+ plugin_attrib = name
+ plugin_multi_attrib = 'bars'
+
+ class TestMultiStanza2(ElementBase):
+ name = 'baz'
+ namespace = 'baz'
+ plugin_attrib = name
+ plugin_multi_attrib = 'bazs'
+
+ register_stanza_plugin(TestStanza, TestMultiStanza1, iterable=True)
+ register_stanza_plugin(TestStanza, TestMultiStanza2, iterable=True)
+
+ stanza = TestStanza()
+ stanza.append(TestMultiStanza1())
+ stanza.append(TestMultiStanza2())
+ stanza.append(TestMultiStanza1())
+ stanza.append(TestMultiStanza2())
+
+ self.check(stanza, """
+ <foo xmlns="foo">
+ <bar xmlns="bar" />
+ <baz xmlns="baz" />
+ <bar xmlns="bar" />
+ <baz xmlns="baz" />
+ </foo>
+ """, use_values=False)
+
+ bars = stanza['bars']
+ bazs = stanza['bazs']
+
+ for bar in bars:
+ self.check(bar, """
+ <bar xmlns="bar" />
+ """)
+
+ for baz in bazs:
+ self.check(baz, """
+ <baz xmlns="baz" />
+ """)
+
+ self.assertEqual(len(bars), 2,
+ "Wrong number of <bar /> stanzas: %s" % len(bars))
+ self.assertEqual(len(bazs), 2,
+ "Wrong number of <baz /> stanzas: %s" % len(bazs))
+
+ def testSetMultiAttrib(self):
+ """Test setting multi_attrib substanzas."""
+
+ class TestStanza(ElementBase):
+ name = 'foo'
+ namespace = 'foo'
+ interfaces = set()
+
+ class TestMultiStanza1(ElementBase):
+ name = 'bar'
+ namespace = 'bar'
+ plugin_attrib = name
+ plugin_multi_attrib = 'bars'
+
+ class TestMultiStanza2(ElementBase):
+ name = 'baz'
+ namespace = 'baz'
+ plugin_attrib = name
+ plugin_multi_attrib = 'bazs'
+
+ register_stanza_plugin(TestStanza, TestMultiStanza1, iterable=True)
+ register_stanza_plugin(TestStanza, TestMultiStanza2, iterable=True)
+
+ stanza = TestStanza()
+ stanza['bars'] = [TestMultiStanza1(), TestMultiStanza1()]
+ stanza['bazs'] = [TestMultiStanza2(), TestMultiStanza2()]
+
+ self.check(stanza, """
+ <foo xmlns="foo">
+ <bar xmlns="bar" />
+ <bar xmlns="bar" />
+ <baz xmlns="baz" />
+ <baz xmlns="baz" />
+ </foo>
+ """, use_values=False)
+
+ self.assertEqual(len(stanza['substanzas']), 4,
+ "Wrong number of substanzas: %s" % len(stanza['substanzas']))
+
+ stanza['bars'] = [TestMultiStanza1()]
+
+ self.check(stanza, """
+ <foo xmlns="foo">
+ <baz xmlns="baz" />
+ <baz xmlns="baz" />
+ <bar xmlns="bar" />
+ </foo>
+ """, use_values=False)
+
+ self.assertEqual(len(stanza['substanzas']), 3,
+ "Wrong number of substanzas: %s" % len(stanza['substanzas']))
+
+
+ def testDelMultiAttrib(self):
+ """Test deleting multi_attrib substanzas."""
+
+ class TestStanza(ElementBase):
+ name = 'foo'
+ namespace = 'foo'
+ interfaces = set()
+
+ class TestMultiStanza1(ElementBase):
+ name = 'bar'
+ namespace = 'bar'
+ plugin_attrib = name
+ plugin_multi_attrib = 'bars'
+
+ class TestMultiStanza2(ElementBase):
+ name = 'baz'
+ namespace = 'baz'
+ plugin_attrib = name
+ plugin_multi_attrib = 'bazs'
+
+ register_stanza_plugin(TestStanza, TestMultiStanza1, iterable=True)
+ register_stanza_plugin(TestStanza, TestMultiStanza2, iterable=True)
+
+ stanza = TestStanza()
+ bars = [TestMultiStanza1(), TestMultiStanza1()]
+ bazs = [TestMultiStanza2(), TestMultiStanza2()]
+
+ stanza['bars'] = bars
+ stanza['bazs'] = bazs
+
+ self.check(stanza, """
+ <foo xmlns="foo">
+ <bar xmlns="bar" />
+ <bar xmlns="bar" />
+ <baz xmlns="baz" />
+ <baz xmlns="baz" />
+ </foo>
+ """, use_values=False)
+
+ del stanza['bars']
+
+ self.check(stanza, """
+ <foo xmlns="foo">
+ <baz xmlns="baz" />
+ <baz xmlns="baz" />
+ </foo>
+ """, use_values=False)
+
+ self.assertEqual(len(stanza['substanzas']), 2,
+ "Wrong number of substanzas: %s" % len(stanza['substanzas']))
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase)