def testReply(self): """Test creating a reply stanza.""" stanza = StanzaBase() stanza['to'] = "*****@*****.**" stanza['from'] = "*****@*****.**" stanza['payload'] = ET.Element("{foo}foo") stanza = stanza.reply() self.assertTrue(str(stanza['to'] == "*****@*****.**"), "Stanza reply did not change 'to' attribute.") self.assertTrue(stanza['payload'] == [], "Stanza reply did not empty stanza payload.")
def testClear(self): """Test clearing a stanza.""" stanza = StanzaBase() stanza['to'] = '*****@*****.**' stanza['payload'] = ET.Element("{foo}foo") stanza.clear() self.assertTrue( stanza['payload'] == [], "Stanza payload was not cleared after calling .clear()") self.assertTrue( str(stanza['to']) == "*****@*****.**", "Stanza attributes were not preserved after calling .clear()")
def testItemsEvent(self): """Testing message/pubsub_event/items/item & retract mix""" msg = self.Message() item = pubsub.EventItem() item2 = pubsub.EventItem() pl = ET.Element('{http://netflint.net/protocol/test}test', { 'failed': '3', 'passed': '24' }) pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', { 'total': '27', 'failed': '3' }) item2['payload'] = pl2 retract = pubsub.EventRetract() retract['id'] = 'aabbcc' item['payload'] = pl item['id'] = 'abc123' item2['id'] = '123abc' msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items'].append(retract) msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items']['node'] = 'cheese' msg['type'] = 'normal' self.check( msg, """ <message type="normal"> <event xmlns="http://jabber.org/protocol/pubsub#event"> <items node="cheese"> <item id="abc123"> <test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" /> </item><retract id="aabbcc" /> <item id="123abc"> <test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" /> </item> </items> </event> </message>""")
def testPayload(self): """Test the 'payload' interface of StanzaBase.""" stanza = StanzaBase() self.assertTrue(stanza['payload'] == [], "Empty stanza does not have an empty payload.") stanza['payload'] = ET.Element("{foo}foo") self.assertTrue( len(stanza['payload']) == 1, "Stanza contents and payload do not match.") stanza['payload'] = ET.Element('{bar}bar') self.assertTrue( len(stanza['payload']) == 2, "Stanza payload was not appended.") del stanza['payload'] self.assertTrue(stanza['payload'] == [], "Stanza payload not cleared after deletion.") stanza['payload'] = [ET.Element('{foo}foo'), ET.Element('{bar}bar')] self.assertTrue( len(stanza['payload']) == 2, "Adding multiple elements to stanza's payload did not work.")
def match(self, xml): """ Compare a stanza's XML contents to an XPath expression. If the value of :data:`IGNORE_NS` is set to ``True``, then XPath expressions will be matched without using namespaces. :param xml: The :class:`~slixmpp.xmlstream.stanzabase.ElementBase` stanza to compare against. """ if hasattr(xml, 'xml'): xml = xml.xml x = ET.Element('x') x.append(xml) return x.find(self._criteria) is not None
def testItemEvent(self): """Testing message/pubsub_event/items/item""" msg = self.Message() item = pubsub.EventItem() pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) item['payload'] = pl item['id'] = 'abc123' msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items']['node'] = 'cheese' msg['type'] = 'normal' self.check(msg, """ <message type="normal"> <event xmlns="http://jabber.org/protocol/pubsub#event"> <items node="cheese"> <item id="abc123"> <test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" /> </item> </items> </event> </message>""")
def match(self, xml): """ Compare a stanza's XML contents to an XPath expression. If the value of :data:`IGNORE_NS` is set to ``True``, then XPath expressions will be matched without using namespaces. .. warning:: In Python 2.6 and 3.1 the ElementTree :meth:`~xml.etree.ElementTree.Element.find()` method does not support attribute selectors in the XPath expression. :param xml: The :class:`~slixmpp.xmlstream.stanzabase.ElementBase` stanza to compare against. """ if hasattr(xml, 'xml'): xml = xml.xml x = ET.Element('x') x.append(xml) return x.find(self._criteria) is not None
def setup(self, xml): # Don't create XML for the plugin self.xml = ET.Element('')
def set_bar(self, value): wrapper = ET.Element("{foo}wrapper") bar = ET.Element("{foo}bar") bar.text = value wrapper.append(bar) self.xml.append(wrapper)
def setup(self, xml=None): self.xml = ET.Element('') return True