diff options
author | Nathan Fritz <nathan@andyet.net> | 2010-08-19 16:09:47 -0700 |
---|---|---|
committer | Nathan Fritz <nathan@andyet.net> | 2010-08-19 16:09:47 -0700 |
commit | d150b35464742de7af9b3105bc7eeb55171b96ee (patch) | |
tree | f1dce9115efbe4c85d37bc27d6ae35f1e937a043 /tests/test_iqstanzas.py | |
parent | 21b7109c06695955632692814fed11b3717e0fc7 (diff) | |
parent | e4240dd593207a5912de996c42451b3946f113b2 (diff) | |
download | slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.tar.gz slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.tar.bz2 slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.tar.xz slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.zip |
fixed todo merge
Diffstat (limited to 'tests/test_iqstanzas.py')
-rw-r--r-- | tests/test_iqstanzas.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/test_iqstanzas.py b/tests/test_iqstanzas.py new file mode 100644 index 00000000..2dabc5e9 --- /dev/null +++ b/tests/test_iqstanzas.py @@ -0,0 +1,90 @@ +from . sleektest import * +from sleekxmpp.xmlstream.stanzabase import ET + + +class TestIqStanzas(SleekTest): + + def tearDown(self): + """Shutdown the XML stream after testing.""" + self.streamClose() + + def testSetup(self): + """Test initializing default Iq values.""" + iq = self.Iq() + self.checkIq(iq, """ + <iq id="0" /> + """) + + def testPayload(self): + """Test setting Iq stanza payload.""" + iq = self.Iq() + iq.setPayload(ET.Element('{test}tester')) + self.checkIq(iq, """ + <iq id="0"> + <tester xmlns="test" /> + </iq> + """, use_values=False) + + + def testUnhandled(self): + """Test behavior for Iq.unhandled.""" + self.streamStart() + self.streamRecv(""" + <iq id="test" type="get"> + <query xmlns="test" /> + </iq> + """) + + iq = self.Iq() + iq['id'] = 'test' + iq['error']['condition'] = 'feature-not-implemented' + iq['error']['text'] = 'No handlers registered for this request.' + + self.streamSendIq(iq, """ + <iq id="test" type="error"> + <error type="cancel"> + <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /> + <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> + No handlers registered for this request. + </text> + </error> + </iq> + """) + + def testQuery(self): + """Test modifying query element of Iq stanzas.""" + iq = self.Iq() + + iq['query'] = 'query_ns' + self.checkIq(iq, """ + <iq id="0"> + <query xmlns="query_ns" /> + </iq> + """) + + iq['query'] = 'query_ns2' + self.checkIq(iq, """ + <iq id="0"> + <query xmlns="query_ns2" /> + </iq> + """) + + self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") + + del iq['query'] + self.checkIq(iq, """ + <iq id="0" /> + """) + + def testReply(self): + """Test setting proper result type in Iq replies.""" + iq = self.Iq() + iq['to'] = 'user@localhost' + iq['type'] = 'get' + iq.reply() + + self.checkIq(iq, """ + <iq id="0" type="result" /> + """) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas) |