test: define the constants JIDs and profiles as lists

This commit is contained in:
souliane 2014-01-09 11:18:33 +01:00
commit db832c1f6b

View file

@ -38,26 +38,26 @@ class XEP_0085Test(helpers.SatTestCase):
def test_messageReceived(self):
self.host.memory.init()
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE)
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.PROFILE[0])
for state in plugin.CHAT_STATES:
xml = u"""
<message type="chat" from="%s" to="%s" id="test_1">
%s
<%s xmlns='%s'/>
</message>
""" % (Const.TEST_JID_2_STR,
Const.TEST_JID_STR,
""" % (Const.JID_STR[1],
Const.JID_STR[0],
"<body>test</body>" if state == "active" else "",
state, plugin.NS_CHAT_STATES)
stanza = parseXml(xml.encode("utf-8"))
self.host.bridge.expectCall("chatStateReceived", u"sender@example.net/house", state, Const.TEST_PROFILE)
self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.TEST_PROFILE)
self.host.bridge.expectCall("chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0])
self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.PROFILE[0])
def test_sendMessageTrigger(self):
self.host.memory.init()
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE)
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.PROFILE[0])
for state in plugin.CHAT_STATES:
mess_data = {"to": Const.TEST_JID,
mess_data = {"to": Const.JID[0],
"type": "chat",
"message": "content",
"extra": {} if state == "active" else {"chat_state": state}}
@ -65,14 +65,14 @@ class XEP_0085Test(helpers.SatTestCase):
<message type="chat" from="%s" to="%s" id="test_1">
%s
</message>
""" % (Const.TEST_JID_2_STR, Const.TEST_JID_STR,
""" % (Const.JID_STR[1], Const.JID_STR[0],
("<body>%s</body>" % mess_data['message']) if state == "active" else "")
mess_data['xml'] = parseXml(stanza.encode("utf-8"))
expected = deepcopy(mess_data['xml'])
expected.addElement(state, plugin.NS_CHAT_STATES)
treatments = defer.Deferred()
self.plugin.sendMessageTrigger(mess_data, treatments, Const.TEST_PROFILE)
self.plugin.sendMessageTrigger(mess_data, treatments, Const.PROFILE[0])
xml = treatments.callbacks[0][0][0](mess_data)
# cancel the timer to not block the process
self.plugin.map[Const.TEST_PROFILE][Const.TEST_JID.userhostJID()].timer.cancel()
self.plugin.map[Const.PROFILE[0]][Const.JID[0].userhostJID()].timer.cancel()
self.assertEqualXML(xml['xml'].toXml().encode("utf-8"), expected.toXml().encode("utf-8"))