mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
0fffbb8200
Moved SleekTest to sleekxmpp.test. Organized test suites by their focus. - Suites focused on testing stanza objects are named test_stanza_X.py - Suites focused on testing stream behavior are name test_stream_X.py
90 lines
2.4 KiB
Python
90 lines
2.4 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, """
|
|
<iq id="0" />
|
|
""")
|
|
|
|
def testPayload(self):
|
|
"""Test setting Iq stanza payload."""
|
|
iq = self.Iq()
|
|
iq.setPayload(ET.Element('{test}tester'))
|
|
self.check_iq(iq, """
|
|
<iq id="0">
|
|
<tester xmlns="test" />
|
|
</iq>
|
|
""", use_values=False)
|
|
|
|
|
|
def testUnhandled(self):
|
|
"""Test behavior for Iq.unhandled."""
|
|
self.stream_start()
|
|
self.stream_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.stream_send_iq(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, """
|
|
<iq id="0">
|
|
<query xmlns="query_ns" />
|
|
</iq>
|
|
""")
|
|
|
|
iq['query'] = 'query_ns2'
|
|
self.check_iq(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, """
|
|
<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, """
|
|
<iq id="0" type="result" />
|
|
""")
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas)
|