'Test manipulating substanzas of a stanza object.'

def testSubStanzas(self):

    class TestSubStanza(ElementBase, ):
        name = 'foobar'
        namespace = 'foo'
        interfaces = set(('qux',))
    class TestStanza(ElementBase, ):
        name = 'foo'
        namespace = 'foo'
        interfaces = set(('bar', 'baz'))
    register_stanza_plugin(TestStanza, TestSubStanza, iterable=True)
    stanza = TestStanza()
    substanza1 = TestSubStanza()
    substanza2 = TestSubStanza()
    substanza1['qux'] = 'a'
    substanza2['qux'] = 'b'
    self.failUnless((len(stanza) == 0), 'Incorrect    empty    stanza    size.')
    stanza.append(substanza1)
    self.check(stanza, '\n                                        <foo    xmlns="foo">\n                                                <foobar    qux="a"    />\n                                        </foo>\n                                ', use_values=False)
    self.failUnless((len(stanza) == 1), 'Incorrect    stanza    size    with    1    substanza.')
    stanza.append(substanza2)
    self.check(stanza, '\n                                        <foo    xmlns="foo">\n                                                <foobar    qux="a"    />\n                                                <foobar    qux="b"    />\n                                        </foo>\n                                ', use_values=False)
    self.failUnless((len(stanza) == 2), 'Incorrect    stanza    size    with    2    substanzas.')
    stanza.pop(0)
    self.check(stanza, '\n                                        <foo    xmlns="foo">\n                                                <foobar    qux="b"    />\n                                        </foo>\n                                ', use_values=False)
    stanza.append(substanza1)
    results = []
    for substanza in stanza:
        results.append(substanza['qux'])
    self.failUnless((results == ['b', 'a']), ('Iteration    over    substanzas    failed:    %s.' % str(results)))
