2013-07-26 11:02:26 +00:00
|
|
|
import unittest
|
2014-07-17 12:19:04 +00:00
|
|
|
from slixmpp.test import SlixTest
|
|
|
|
from slixmpp.xmlstream.stanzabase import ET
|
2010-07-30 03:58:25 +00:00
|
|
|
|
|
|
|
|
2014-07-17 12:19:04 +00:00
|
|
|
class TestIqStanzas(SlixTest):
|
2010-07-30 03:58:25 +00:00
|
|
|
|
|
|
|
def testSetup(self):
|
|
|
|
"""Test initializing default Iq values."""
|
|
|
|
iq = self.Iq()
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="0" />
|
|
|
|
""")
|
2010-08-06 00:23:07 +00:00
|
|
|
|
2010-07-30 03:58:25 +00:00
|
|
|
def testPayload(self):
|
|
|
|
"""Test setting Iq stanza payload."""
|
|
|
|
iq = self.Iq()
|
2014-09-21 16:51:06 +00:00
|
|
|
iq.set_payload(ET.Element('{test}tester'))
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="0">
|
|
|
|
<tester xmlns="test" />
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
|
|
|
|
def testUnhandled(self):
|
|
|
|
"""Test behavior for Iq.unhandled."""
|
2010-10-07 13:22:27 +00:00
|
|
|
self.stream_start()
|
2010-11-05 18:45:58 +00:00
|
|
|
self.recv("""
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="test" type="get">
|
|
|
|
<query xmlns="test" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
iq = self.Iq()
|
2010-07-30 03:58:25 +00:00
|
|
|
iq['id'] = 'test'
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['error']['condition'] = 'feature-not-implemented'
|
|
|
|
iq['error']['text'] = 'No handlers registered for this request.'
|
2010-07-30 03:58:25 +00:00
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.send(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<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'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="query_ns" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
iq['query'] = 'query_ns2'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="0">
|
|
|
|
<query xmlns="query_ns2" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2018-10-08 21:25:23 +00:00
|
|
|
self.assertTrue(iq['query'] == 'query_ns2', "Query namespace doesn't match")
|
2010-07-30 03:58:25 +00:00
|
|
|
|
2010-08-06 00:23:07 +00:00
|
|
|
del iq['query']
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="0" />
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testReply(self):
|
|
|
|
"""Test setting proper result type in Iq replies."""
|
|
|
|
iq = self.Iq()
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['to'] = 'user@localhost'
|
|
|
|
iq['type'] = 'get'
|
2015-02-12 11:23:47 +00:00
|
|
|
iq = iq.reply()
|
2010-07-30 03:58:25 +00:00
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-30 03:58:25 +00:00
|
|
|
<iq id="0" type="result" />
|
|
|
|
""")
|
|
|
|
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas)
|