import unittest from slixmpp.test import SlixTest from slixmpp.xmlstream.stanzabase import ET class TestIqStanzas(SlixTest): def testSetup(self): """Test initializing default Iq values.""" iq = self.Iq() self.check(iq, """ """) def testPayload(self): """Test setting Iq stanza payload.""" iq = self.Iq() iq.set_payload(ET.Element('{test}tester')) self.check(iq, """ """, use_values=False) def testUnhandled(self): """Test behavior for Iq.unhandled.""" self.stream_start() self.recv(""" """) iq = self.Iq() iq['id'] = 'test' iq['error']['condition'] = 'feature-not-implemented' iq['error']['text'] = 'No handlers registered for this request.' self.send(iq, """ No handlers registered for this request. """) def testQuery(self): """Test modifying query element of Iq stanzas.""" iq = self.Iq() iq['query'] = 'query_ns' self.check(iq, """ """) iq['query'] = 'query_ns2' self.check(iq, """ """) self.assertTrue(iq['query'] == 'query_ns2', "Query namespace doesn't match") del iq['query'] self.check(iq, """ """) def testReply(self): """Test setting proper result type in Iq replies.""" iq = self.Iq() iq['to'] = 'user@localhost' iq['type'] = 'get' iq = iq.reply() self.check(iq, """ """) suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas)