Rename to slixmpp
[slixmpp.git] / tests / test_stanza_iq.py
blob26dbc29598ac46ce857f22370f4b5c50f9df3755
1 import unittest
2 from slixmpp.test import SlixTest
3 from slixmpp.xmlstream.stanzabase import ET
6 class TestIqStanzas(SlixTest):
8 def tearDown(self):
9 """Shutdown the XML stream after testing."""
10 self.stream_close()
12 def testSetup(self):
13 """Test initializing default Iq values."""
14 iq = self.Iq()
15 self.check(iq, """
16 <iq id="0" />
17 """)
19 def testPayload(self):
20 """Test setting Iq stanza payload."""
21 iq = self.Iq()
22 iq.setPayload(ET.Element('{test}tester'))
23 self.check(iq, """
24 <iq id="0">
25 <tester xmlns="test" />
26 </iq>
27 """, use_values=False)
30 def testUnhandled(self):
31 """Test behavior for Iq.unhandled."""
32 self.stream_start()
33 self.recv("""
34 <iq id="test" type="get">
35 <query xmlns="test" />
36 </iq>
37 """)
39 iq = self.Iq()
40 iq['id'] = 'test'
41 iq['error']['condition'] = 'feature-not-implemented'
42 iq['error']['text'] = 'No handlers registered for this request.'
44 self.send(iq, """
45 <iq id="test" type="error">
46 <error type="cancel">
47 <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
48 <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">
49 No handlers registered for this request.
50 </text>
51 </error>
52 </iq>
53 """)
55 def testQuery(self):
56 """Test modifying query element of Iq stanzas."""
57 iq = self.Iq()
59 iq['query'] = 'query_ns'
60 self.check(iq, """
61 <iq id="0">
62 <query xmlns="query_ns" />
63 </iq>
64 """)
66 iq['query'] = 'query_ns2'
67 self.check(iq, """
68 <iq id="0">
69 <query xmlns="query_ns2" />
70 </iq>
71 """)
73 self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match")
75 del iq['query']
76 self.check(iq, """
77 <iq id="0" />
78 """)
80 def testReply(self):
81 """Test setting proper result type in Iq replies."""
82 iq = self.Iq()
83 iq['to'] = 'user@localhost'
84 iq['type'] = 'get'
85 iq.reply()
87 self.check(iq, """
88 <iq id="0" type="result" />
89 """)
91 suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas)