comparison src/test/test_plugin_xep_0085.py @ 786:c3acc1298a2f

test: FakeMemory inherits from Memory + more helpers basic support + cleaning
author souliane <souliane@mailoo.org>
date Sun, 05 Jan 2014 13:04:54 +0100
parents 27581cddb758
children 2136be5a44a8
comparison
equal deleted inserted replaced
785:ff9a52077b36 786:c3acc1298a2f
38 38
39 def test_messageReceived(self): 39 def test_messageReceived(self):
40 self.host.memory.init() 40 self.host.memory.init()
41 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE) 41 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE)
42 for state in plugin.CHAT_STATES: 42 for state in plugin.CHAT_STATES:
43 xml = """ 43 xml = u"""
44 <message type="chat" from="sender@example.net/house" to="sender@example.net/house" id="test_1"> 44 <message type="chat" from="%s" to="%s" id="test_1">
45 %s 45 %s
46 <%s xmlns='http://jabber.org/protocol/chatstates'/> 46 <%s xmlns='%s'/>
47 </message> 47 </message>
48 """ % ("<body>test</body>" if state == "active" else "", state) 48 """ % (Const.TEST_JID_2_STR,
49 stanza = parseXml(xml) 49 Const.TEST_JID_STR,
50 "<body>test</body>" if state == "active" else "",
51 state, plugin.NS_CHAT_STATES)
52 stanza = parseXml(xml.encode("utf-8"))
50 self.host.bridge.expectCall("chatStateReceived", u"sender@example.net/house", state, Const.TEST_PROFILE) 53 self.host.bridge.expectCall("chatStateReceived", u"sender@example.net/house", state, Const.TEST_PROFILE)
51 self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.TEST_PROFILE) 54 self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.TEST_PROFILE)
52 55
53 def test_sendMessageTrigger(self): 56 def test_sendMessageTrigger(self):
54 self.host.memory.init() 57 self.host.memory.init()
55 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE) 58 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE)
56 for state in plugin.CHAT_STATES: 59 for state in plugin.CHAT_STATES:
57 mess_data = {"to": "test@example.org/SàT", 60 mess_data = {"to": Const.TEST_JID,
58 "type": "chat", 61 "type": "chat",
59 "message": "content", 62 "message": "content",
60 "extra": {} if state == "active" else {"chat_state": state}} 63 "extra": {} if state == "active" else {"chat_state": state}}
61 mess_data['xml'] = parseXml(""" 64 stanza = u"""
62 <message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1"> 65 <message type="chat" from="%s" to="%s" id="test_1">
63 %s 66 %s
64 </message> 67 </message>
65 """ % (("<body>%s</body>" % mess_data['message']) if state == "active" else "",)) 68 """ % (Const.TEST_JID_2_STR, Const.TEST_JID_STR,
69 ("<body>%s</body>" % mess_data['message']) if state == "active" else "")
70 mess_data['xml'] = parseXml(stanza.encode("utf-8"))
66 expected = deepcopy(mess_data['xml']) 71 expected = deepcopy(mess_data['xml'])
67 expected.addElement(state, plugin.NS_CHAT_STATES) 72 expected.addElement(state, plugin.NS_CHAT_STATES)
68 treatments = defer.Deferred() 73 treatments = defer.Deferred()
69 self.plugin.sendMessageTrigger(mess_data, treatments, Const.TEST_PROFILE) 74 self.plugin.sendMessageTrigger(mess_data, treatments, Const.TEST_PROFILE)
70 xml = treatments.callbacks[0][0][0](mess_data) 75 xml = treatments.callbacks[0][0][0](mess_data)