Add the 'connecting' event
[slixmpp.git] / tests / live_test.py
blob327657a7e2508944e9ae8c8207b8809c02eb7b4e
1 import logging
3 from slixmpp.test import *
6 class TestLiveStream(SlixTest):
7 """
8 Test that we can test a live stanza stream.
9 """
11 def tearDown(self):
12 self.stream_close()
14 def testClientConnection(self):
15 """Test that we can interact with a live ClientXMPP instance."""
16 self.stream_start(mode='client',
17 socket='live',
18 skip=False,
19 jid='user@localhost/test',
20 password='user')
22 # Use sid=None to ignore any id sent by the server since
23 # we can't know it in advance.
24 self.recv_header(sfrom='localhost', sid=None)
25 self.send_header(sto='localhost')
26 self.recv_feature("""
27 <stream:features>
28 <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
29 <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
30 <mechanism>DIGEST-MD5</mechanism>
31 <mechanism>PLAIN</mechanism>
32 </mechanisms>
33 </stream:features>
34 """)
35 self.send_feature("""
36 <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
37 """)
38 self.recv_feature("""
39 <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
40 """)
41 self.send_header(sto='localhost')
42 self.recv_header(sfrom='localhost', sid=None)
43 self.recv_feature("""
44 <stream:features>
45 <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
46 <mechanism>DIGEST-MD5</mechanism>
47 <mechanism>PLAIN</mechanism>
48 </mechanisms>
49 </stream:features>
50 """)
51 self.send_feature("""
52 <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl"
53 mechanism="PLAIN">AHVzZXIAdXNlcg==</auth>
54 """)
55 self.recv_feature("""
56 <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
57 """)
58 self.send_header(sto='localhost')
59 self.recv_header(sfrom='localhost', sid=None)
60 self.recv_feature("""
61 <stream:features>
62 <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" />
63 <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
64 </stream:features>
65 """)
67 # Should really use send, but our Iq stanza objects
68 # can't handle bind element payloads yet.
69 self.send_feature("""
70 <iq type="set" id="1">
71 <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
72 <resource>test</resource>
73 </bind>
74 </iq>
75 """)
76 self.recv_feature("""
77 <iq type="result" id="1">
78 <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
79 <jid>user@localhost/test</jid>
80 </bind>
81 </iq>
82 """)
83 self.stream_close()
86 suite = unittest.TestLoader().loadTestsFromTestCase(TestLiveStream)
88 if __name__ == '__main__':
89 logging.basicConfig(level=logging.DEBUG,
90 format='%(levelname)-8s %(message)s')
92 tests = unittest.TestSuite([suite])
93 result = unittest.TextTestRunner(verbosity=2).run(tests)
94 test_ns = 'http://andyet.net/protocol/tests'
95 print("<tests xmlns='%s' %s %s %s %s />" % (
96 test_ns,
97 'ran="%s"' % result.testsRun,
98 'errors="%s"' % len(result.errors),
99 'fails="%s"' % len(result.failures),
100 'success="%s"' % result.wasSuccessful()))