Doesn't fail if host has NO SRV record
[slixmpp.git] / tests / test_stanza_iq.py
blob42e4dcde3eef1aa982cedb0a48e2d3c7d159abe7
1 from sleekxmpp.test import *
2 from sleekxmpp.xmlstream.stanzabase import ET
5 class TestIqStanzas(SleekTest):
7 def tearDown(self):
8 """Shutdown the XML stream after testing."""
9 self.stream_close()
11 def testSetup(self):
12 """Test initializing default Iq values."""
13 iq = self.Iq()
14 self.check(iq, """
15 <iq id="0" />
16 """)
18 def testPayload(self):
19 """Test setting Iq stanza payload."""
20 iq = self.Iq()
21 iq.setPayload(ET.Element('{test}tester'))
22 self.check(iq, """
23 <iq id="0">
24 <tester xmlns="test" />
25 </iq>
26 """, use_values=False)
29 def testUnhandled(self):
30 """Test behavior for Iq.unhandled."""
31 self.stream_start()
32 self.recv("""
33 <iq id="test" type="get">
34 <query xmlns="test" />
35 </iq>
36 """)
38 iq = self.Iq()
39 iq['id'] = 'test'
40 iq['error']['condition'] = 'feature-not-implemented'
41 iq['error']['text'] = 'No handlers registered for this request.'
43 self.send(iq, """
44 <iq id="test" type="error">
45 <error type="cancel">
46 <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
47 <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">
48 No handlers registered for this request.
49 </text>
50 </error>
51 </iq>
52 """)
54 def testQuery(self):
55 """Test modifying query element of Iq stanzas."""
56 iq = self.Iq()
58 iq['query'] = 'query_ns'
59 self.check(iq, """
60 <iq id="0">
61 <query xmlns="query_ns" />
62 </iq>
63 """)
65 iq['query'] = 'query_ns2'
66 self.check(iq, """
67 <iq id="0">
68 <query xmlns="query_ns2" />
69 </iq>
70 """)
72 self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match")
74 del iq['query']
75 self.check(iq, """
76 <iq id="0" />
77 """)
79 def testReply(self):
80 """Test setting proper result type in Iq replies."""
81 iq = self.Iq()
82 iq['to'] = 'user@localhost'
83 iq['type'] = 'get'
84 iq.reply()
86 self.check(iq, """
87 <iq id="0" type="result" />
88 """)
90 suite = unittest.TestLoader().loadTestsFromTestCase(TestIqStanzas)