def test_legacy(self): """ Test legacy operations of exceptionFromStanza. Given a realistic stanza with only legacy (pre-XMPP) error information, check if a sane exception is returned. Using this stanza:: <message type='error' to='[email protected]/Home' from='*****@*****.**'> <body>Are you there?</body> <error code='502'>Unable to resolve hostname.</error> </message> """ stanza = domish.Element((None, 'stanza')) p = stanza.addElement('body', content='Are you there?') e = stanza.addElement('error', content='Unable to resolve hostname.') e['code'] = '502' result = error.exceptionFromStanza(stanza) self.assert_(isinstance(result, error.StanzaError)) self.assertEquals('service-unavailable', result.condition) self.assertEquals('wait', result.type) self.assertEquals('Unable to resolve hostname.', result.text) self.assertEquals([p], result.children)
def callback(iq): """ Handle iq response by firing associated deferred. """ if getattr(iq, 'handled', False): return try: d = xs.iqDeferreds[iq["id"]] except KeyError: pass else: del xs.iqDeferreds[iq["id"]] iq.handled = True if iq['type'] == 'error': d.errback(error.exceptionFromStanza(iq)) else: d.callback(iq)
def test_basic(self): """ Test basic operations of exceptionFromStanza. Given a realistic stanza, check if a sane exception is returned. Using this stanza:: <iq type='error' from='pubsub.shakespeare.lit' to='[email protected]/barracks' id='subscriptions1'> <pubsub xmlns='http://jabber.org/protocol/pubsub'> <subscriptions/> </pubsub> <error type='cancel'> <feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> <unsupported xmlns='http://jabber.org/protocol/pubsub#errors' feature='retrieve-subscriptions'/> </error> </iq> """ stanza = domish.Element((None, 'stanza')) p = stanza.addElement(('http://jabber.org/protocol/pubsub', 'pubsub')) p.addElement('subscriptions') e = stanza.addElement('error') e['type'] = 'cancel' e.addElement((NS_XMPP_STANZAS, 'feature-not-implemented')) uc = e.addElement( ('http://jabber.org/protocol/pubsub#errors', 'unsupported')) uc['feature'] = 'retrieve-subscriptions' result = error.exceptionFromStanza(stanza) self.assert_(isinstance(result, error.StanzaError)) self.assertEquals('feature-not-implemented', result.condition) self.assertEquals('cancel', result.type) self.assertEquals(uc, result.appCondition) self.assertEquals([p], result.children)
def test_basic(self): """ Test basic operations of exceptionFromStanza. Given a realistic stanza, check if a sane exception is returned. Using this stanza:: <iq type='error' from='pubsub.shakespeare.lit' to='[email protected]/barracks' id='subscriptions1'> <pubsub xmlns='http://jabber.org/protocol/pubsub'> <subscriptions/> </pubsub> <error type='cancel'> <feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> <unsupported xmlns='http://jabber.org/protocol/pubsub#errors' feature='retrieve-subscriptions'/> </error> </iq> """ stanza = domish.Element((None, 'stanza')) p = stanza.addElement(('http://jabber.org/protocol/pubsub', 'pubsub')) p.addElement('subscriptions') e = stanza.addElement('error') e['type'] = 'cancel' e.addElement((NS_XMPP_STANZAS, 'feature-not-implemented')) uc = e.addElement(('http://jabber.org/protocol/pubsub#errors', 'unsupported')) uc['feature'] = 'retrieve-subscriptions' result = error.exceptionFromStanza(stanza) self.assert_(isinstance(result, error.StanzaError)) self.assertEquals('feature-not-implemented', result.condition) self.assertEquals('cancel', result.type) self.assertEquals(uc, result.appCondition) self.assertEquals([p], result.children)