Rename to slixmpp
[slixmpp.git] / tests / test_stream_xep_0085.py
blob2de176746e043664da08878d1076ba4076552194
1 import time
3 import unittest
4 from slixmpp.test import SlixTest
7 class TestStreamChatStates(SlixTest):
9 def tearDown(self):
10 self.stream_close()
12 def testChatStates(self):
13 self.stream_start(mode='client', plugins=['xep_0030', 'xep_0085'])
15 results = []
17 def handle_state(msg):
18 results.append(msg['chat_state'])
20 self.xmpp.add_event_handler('chatstate_active', handle_state)
21 self.xmpp.add_event_handler('chatstate_inactive', handle_state)
22 self.xmpp.add_event_handler('chatstate_paused', handle_state)
23 self.xmpp.add_event_handler('chatstate_gone', handle_state)
24 self.xmpp.add_event_handler('chatstate_composing', handle_state)
26 self.recv("""
27 <message>
28 <active xmlns="http://jabber.org/protocol/chatstates" />
29 </message>
30 """)
31 self.recv("""
32 <message>
33 <inactive xmlns="http://jabber.org/protocol/chatstates" />
34 </message>
35 """)
36 self.recv("""
37 <message>
38 <paused xmlns="http://jabber.org/protocol/chatstates" />
39 </message>
40 """)
41 self.recv("""
42 <message>
43 <composing xmlns="http://jabber.org/protocol/chatstates" />
44 </message>
45 """)
46 self.recv("""
47 <message>
48 <gone xmlns="http://jabber.org/protocol/chatstates" />
49 </message>
50 """)
52 # Give event queue time to process
53 time.sleep(0.3)
54 expected = ['active', 'inactive', 'paused', 'composing', 'gone']
55 self.failUnless(results == expected,
56 "Chat state event not handled: %s" % results)
59 suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamChatStates)