mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-23 19:19:53 +00:00
d0c506f930
* check_stanza does not require stanza_class parameter. Introspection! * check_message, check_iq, and check_presence removed -- use check instead. * stream_send_stanza, stream_send_message, stream_send_iq, and stream_send_presence removed -- use send instead. * Use recv instead of recv_message, recv_presence, etc. * check_jid instead of check_JID * stream_start may accept multi=True to return a new SleekTest instance for testing multiple streams at once.
90 lines
2.3 KiB
Python
90 lines
2.3 KiB
Python
from sleekxmpp.test import *
|
|
from sleekxmpp.xmlstream.stanzabase import ET
|
|
|
|
|
|
class TestIqStanzas(SleekTest):
|
|
|
|
def tearDown(self):
|
|
"""Shutdown the XML stream after testing."""
|
|
self.stream_close()
|
|
|
|
def testSetup(self):
|
|
"""Test initializing default Iq values."""
|
|
iq = self.Iq()
|
|
self.check(iq, """
|
|
<iq id="0" />
|
|
""")
|
|
|
|
def testPayload(self):
|
|
"""Test setting Iq stanza payload."""
|
|
iq = self.Iq()
|
|
iq.setPayload(ET.Element('{test}tester'))
|
|
self.check(iq, """
|
|
<iq id="0">
|
|
<tester xmlns="test" />
|
|
</iq>
|
|
""", use_values=False)
|
|
|
|
|
|
def testUnhandled(self):
|
|
"""Test behavior for Iq.unhandled."""
|
|
self.stream_start()
|
|
self.recv("""
|
|
<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.send(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.check(iq, """
|
|
<iq id="0">
|
|
<query xmlns="query_ns" />
|
|
</iq>
|
|
""")
|
|
|
|
iq['query'] = 'query_ns2'
|
|
self.check(iq, """
|
|
<iq id="0">
|
|
<query xmlns="query_ns2" />
|
|
</iq>
|
|
""")
|
|
|
|
self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match")
|
|
|
|
del iq['query']
|
|
self.check(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.check(iq, """
|
|
<iq id="0" type="result" />
|
|
""")
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas)
|