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

@ -48,15 +48,15 @@ class XEP_0033Test(helpers.SatTestCase):
<address type='bcc' jid='%s'/>
</addresses>
</message>
""" % (Const.TEST_JID_2_STR, self.host.getClientHostJid(Const.TEST_PROFILE),
Const.TEST_JID_STR, Const.TEST_JID_2_STR, Const.TEST_JID_3_STR)
""" % (Const.JID_STR[1], self.host.getClientHostJid(Const.PROFILE[0]),
Const.JID_STR[0], Const.JID_STR[1], Const.JID_STR[2])
stanza = parseXml(xml.encode("utf-8"))
treatments = defer.Deferred()
self.plugin.messageReceivedTrigger(stanza, treatments, Const.TEST_PROFILE)
self.plugin.messageReceivedTrigger(stanza, treatments, Const.PROFILE[0])
data = {'extra': {}}
def cb(data):
expected = ('to', Const.TEST_JID_STR, 'cc', Const.TEST_JID_2_STR, 'bcc', Const.TEST_JID_3_STR)
expected = ('to', Const.JID_STR[0], 'cc', Const.JID_STR[1], 'bcc', Const.JID_STR[2])
msg = 'Expected: %s\nGot: %s' % (expected, data['extra']['addresses'])
self.assertEqual(data['extra']['addresses'], '%s:%s\n%s:%s\n%s:%s\n' % expected, msg)
@ -64,18 +64,18 @@ class XEP_0033Test(helpers.SatTestCase):
treatments.callback(data)
def test_sendMessageTrigger(self):
mess_data = {"to": self.host.getClientHostJid(Const.TEST_PROFILE),
mess_data = {"to": self.host.getClientHostJid(Const.PROFILE[0]),
"type": "chat",
"message": "content",
"extra": {}
}
addresses = ('to', Const.TEST_JID_STR, 'cc', Const.TEST_JID_2_STR, 'bcc', Const.TEST_JID_3_STR)
addresses = ('to', Const.JID_STR[0], 'cc', Const.JID_STR[1], 'bcc', Const.JID_STR[2])
mess_data["extra"]["address"] = '%s:%s\n%s:%s\n%s:%s\n' % addresses
original_stanza = u"""
<message type="chat" from="%s" to="%s" id="test_1">
<body>content</body>
</message>
""" % (Const.TEST_JID_2_STR, self.host.getClientHostJid(Const.TEST_PROFILE))
""" % (Const.JID_STR[1], self.host.getClientHostJid(Const.PROFILE[0]))
mess_data['xml'] = parseXml(original_stanza.encode("utf-8"))
expected = deepcopy(mess_data['xml'])
addresses_extra = """
@ -108,7 +108,7 @@ class XEP_0033Test(helpers.SatTestCase):
for to_s in [addresses[1], addresses[3], addresses[5]]:
to_jid = JID(to_s)
host = JID(to_jid.host)
if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.TEST_PROFILE):
if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.PROFILE[0]):
if host not in cache:
sent.append(host)
stored.append(host)
@ -125,17 +125,17 @@ class XEP_0033Test(helpers.SatTestCase):
self.host.memory.init()
treatments = defer.Deferred()
data = deepcopy(mess_data)
self.plugin.sendMessageTrigger(data, treatments, Const.TEST_PROFILE)
self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0])
treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage))
treatments.callback(data)
# feature is supported
self.host.init()
self.host.memory.init()
self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.TEST_PROFILE), Const.TEST_PROFILE)
self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
treatments = defer.Deferred()
data = deepcopy(mess_data)
self.plugin.sendMessageTrigger(data, treatments, Const.TEST_PROFILE)
self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0])
treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored))
treatments.callback(data)
checkSentAndStored()
@ -143,11 +143,11 @@ class XEP_0033Test(helpers.SatTestCase):
# check that a wrong recipient entity is fixed by the backend
self.host.init()
self.host.memory.init()
self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.TEST_PROFILE), Const.TEST_PROFILE)
self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
treatments = defer.Deferred()
data = deepcopy(mess_data)
data["to"] = Const.TEST_JID
self.plugin.sendMessageTrigger(data, treatments, Const.TEST_PROFILE)
data["to"] = Const.JID[0]
self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0])
treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored))
treatments.callback(mess_data)
checkSentAndStored()