Mercurial > libervia-backend
comparison src/test/test_plugin_xep_0085.py @ 792:2136be5a44a8
test: define the constants JIDs and profiles as lists
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 09 Jan 2014 11:18:33 +0100 |
parents | c3acc1298a2f |
children | 1fe00f0c9a91 |
comparison
equal
deleted
inserted
replaced
791:23b0c949b86c | 792:2136be5a44a8 |
---|---|
36 self.host = helpers.FakeSAT() | 36 self.host = helpers.FakeSAT() |
37 self.plugin = plugin.XEP_0085(self.host) | 37 self.plugin = plugin.XEP_0085(self.host) |
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.PROFILE[0]) |
42 for state in plugin.CHAT_STATES: | 42 for state in plugin.CHAT_STATES: |
43 xml = u""" | 43 xml = u""" |
44 <message type="chat" from="%s" to="%s" id="test_1"> | 44 <message type="chat" from="%s" to="%s" id="test_1"> |
45 %s | 45 %s |
46 <%s xmlns='%s'/> | 46 <%s xmlns='%s'/> |
47 </message> | 47 </message> |
48 """ % (Const.TEST_JID_2_STR, | 48 """ % (Const.JID_STR[1], |
49 Const.TEST_JID_STR, | 49 Const.JID_STR[0], |
50 "<body>test</body>" if state == "active" else "", | 50 "<body>test</body>" if state == "active" else "", |
51 state, plugin.NS_CHAT_STATES) | 51 state, plugin.NS_CHAT_STATES) |
52 stanza = parseXml(xml.encode("utf-8")) | 52 stanza = parseXml(xml.encode("utf-8")) |
53 self.host.bridge.expectCall("chatStateReceived", u"sender@example.net/house", state, Const.TEST_PROFILE) | 53 self.host.bridge.expectCall("chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0]) |
54 self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.TEST_PROFILE) | 54 self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.PROFILE[0]) |
55 | 55 |
56 def test_sendMessageTrigger(self): | 56 def test_sendMessageTrigger(self): |
57 self.host.memory.init() | 57 self.host.memory.init() |
58 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.PROFILE[0]) |
59 for state in plugin.CHAT_STATES: | 59 for state in plugin.CHAT_STATES: |
60 mess_data = {"to": Const.TEST_JID, | 60 mess_data = {"to": Const.JID[0], |
61 "type": "chat", | 61 "type": "chat", |
62 "message": "content", | 62 "message": "content", |
63 "extra": {} if state == "active" else {"chat_state": state}} | 63 "extra": {} if state == "active" else {"chat_state": state}} |
64 stanza = u""" | 64 stanza = u""" |
65 <message type="chat" from="%s" to="%s" id="test_1"> | 65 <message type="chat" from="%s" to="%s" id="test_1"> |
66 %s | 66 %s |
67 </message> | 67 </message> |
68 """ % (Const.TEST_JID_2_STR, Const.TEST_JID_STR, | 68 """ % (Const.JID_STR[1], Const.JID_STR[0], |
69 ("<body>%s</body>" % mess_data['message']) if state == "active" else "") | 69 ("<body>%s</body>" % mess_data['message']) if state == "active" else "") |
70 mess_data['xml'] = parseXml(stanza.encode("utf-8")) | 70 mess_data['xml'] = parseXml(stanza.encode("utf-8")) |
71 expected = deepcopy(mess_data['xml']) | 71 expected = deepcopy(mess_data['xml']) |
72 expected.addElement(state, plugin.NS_CHAT_STATES) | 72 expected.addElement(state, plugin.NS_CHAT_STATES) |
73 treatments = defer.Deferred() | 73 treatments = defer.Deferred() |
74 self.plugin.sendMessageTrigger(mess_data, treatments, Const.TEST_PROFILE) | 74 self.plugin.sendMessageTrigger(mess_data, treatments, Const.PROFILE[0]) |
75 xml = treatments.callbacks[0][0][0](mess_data) | 75 xml = treatments.callbacks[0][0][0](mess_data) |
76 # cancel the timer to not block the process | 76 # cancel the timer to not block the process |
77 self.plugin.map[Const.TEST_PROFILE][Const.TEST_JID.userhostJID()].timer.cancel() | 77 self.plugin.map[Const.PROFILE[0]][Const.JID[0].userhostJID()].timer.cancel() |
78 self.assertEqualXML(xml['xml'].toXml().encode("utf-8"), expected.toXml().encode("utf-8")) | 78 self.assertEqualXML(xml['xml'].toXml().encode("utf-8"), expected.toXml().encode("utf-8")) |