diff --git a/src/test/constants.py b/src/test/constants.py
index ad0d5a57..ddf217b4 100644
--- a/src/test/constants.py
+++ b/src/test/constants.py
@@ -18,21 +18,17 @@
# along with this program. If not, see .
from sat.core.i18n import _, D_
-from twisted.words.protocols.jabber.jid import JID
+from twisted.words.protocols.jabber import jid
class Const(object):
- TEST_JID_STR = u"test@example.org/SàT"
- TEST_JID = JID(TEST_JID_STR)
+ PROFILE = ['test_profile', 'test_profile2', 'test_profile3', 'test_profile4']
+ JID_STR = [u"test@example.org/SàT", u"sender@example.net/house", u"sender@example.net/work", u"test@server.net/res"]
+ JID = [jid.JID(jid_s) for jid_s in JID_STR]
- TEST_JID_2_STR = u"sender@example.net/house"
- TEST_JID_2 = JID(TEST_JID_2_STR)
-
- TEST_JID_3_STR = u"sender@example.net/work"
- TEST_JID_3 = JID(TEST_JID_3_STR)
-
- TEST_PROFILE = 'test_profile'
+ MUC_STR = [u"room@chat.server.domain", u"sat_game@chat.server.domain"]
+ MUC = [jid.JID(jid_s) for jid_s in MUC_STR]
NO_SECURITY_LIMIT = -1
SECURITY_LIMIT = 0
diff --git a/src/test/helpers.py b/src/test/helpers.py
index 9358653b..06c62e99 100644
--- a/src/test/helpers.py
+++ b/src/test/helpers.py
@@ -104,7 +104,7 @@ class FakeSAT(object):
return defer.succeed(jid_ if self.memory.hasServerFeature(feature, jid_, profile_key) else None)
def getClientHostJid(self, profile_key):
- return JID(Const.TEST_JID.host)
+ return JID(Const.JID[0].host)
class FakeBridge(object):
@@ -149,7 +149,7 @@ class FakeParams(Params):
def getProfileName(self, profile_key, return_profile_keys=False):
if profile_key == '@DEFAULT@':
- return Const.TEST_PROFILE
+ return Const.PROFILE[0]
elif profile_key == '@NONE@':
raise exceptions.ProfileNotSetError
else:
@@ -222,7 +222,7 @@ class FakeRosterProtocol(SatRosterProtocol):
def __init__(self, host, parent):
SatRosterProtocol.__init__(self, host)
self.parent = parent
- self.addItem(Const.TEST_JID)
+ self.addItem(Const.JID[0])
def addItem(self, jid, *args, **kwargs):
if not args and not kwargs:
@@ -241,7 +241,7 @@ class FakeClient(object):
def __init__(self, host):
self.host = host
self.profile = 'test_profile'
- self.jid = Const.TEST_JID
+ self.jid = Const.JID[0]
self.roster = FakeRosterProtocol(host, self)
def send(self, obj):
diff --git a/src/test/test_core_xmpp.py b/src/test/test_core_xmpp.py
index 6da36414..7aee8b21 100644
--- a/src/test/test_core_xmpp.py
+++ b/src/test/test_core_xmpp.py
@@ -32,11 +32,11 @@ class SatXMPPClientTest(unittest.TestCase):
def setUp(self):
self.host = helpers.FakeSAT()
- self.client = xmpp.SatXMPPClient(self.host, "test_profile", JID("test@example.org"), "test")
+ self.client = xmpp.SatXMPPClient(self.host, Const.PROFILE[0], JID("test@example.org"), "test")
def test_init(self):
"""Check that init values are correctly initialised"""
- self.assertEqual(self.client.profile, "test_profile")
+ self.assertEqual(self.client.profile, Const.PROFILE[0])
print self.client.host
self.assertEqual(self.client.host_app, self.host)
self.assertTrue(isinstance(self.client.client_initialized, defer.Deferred))
@@ -56,7 +56,7 @@ class SatMessageProtocolTest(unittest.TestCase):
"""
stanza = parseXml(xml)
- self.host.bridge.expectCall("newMessage", u"sender@example.net/house", u"test", u"chat", u"test@example.org/SàT", {}, profile="test_profile")
+ self.host.bridge.expectCall("newMessage", u"sender@example.net/house", u"test", u"chat", u"test@example.org/SàT", {}, profile=Const.PROFILE[0])
self.message.onMessage(stanza)
@@ -68,13 +68,13 @@ class SatRosterProtocolTest(unittest.TestCase):
self.roster.parent = helpers.FakeClient(self.host)
def test_onRosterSet(self):
- roster_item = RosterItem(Const.TEST_JID)
+ roster_item = RosterItem(Const.JID[0])
roster_item.name = u"Test Man"
roster_item.subscriptionTo = True
roster_item.subscriptionFrom = True
roster_item.ask = False
roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"])
- self.host.bridge.expectCall("newContact", Const.TEST_JID_STR, {'to': 'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), "test_profile")
+ self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), Const.PROFILE[0])
self.roster.onRosterSet(roster_item)
@@ -86,29 +86,29 @@ class SatPresenceProtocolTest(unittest.TestCase):
self.presence.parent = helpers.FakeClient(self.host)
def test_availableReceived(self):
- self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.TEST_PROFILE)
- self.presence.availableReceived(Const.TEST_JID, 'xa', {None: "test status", 'fr': 'statut de test'}, 15)
+ self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.PROFILE[0])
+ self.presence.availableReceived(Const.JID[0], 'xa', {None: "test status", 'fr': 'statut de test'}, 15)
def test_availableReceived_empty_statuses(self):
- self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "xa", 15, {}, Const.TEST_PROFILE)
- self.presence.availableReceived(Const.TEST_JID, 'xa', None, 15)
+ self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "xa", 15, {}, Const.PROFILE[0])
+ self.presence.availableReceived(Const.JID[0], 'xa', None, 15)
def test_unavailableReceived(self):
- self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "unavailable", 0, {}, Const.TEST_PROFILE)
- self.presence.unavailableReceived(Const.TEST_JID, None)
+ self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "unavailable", 0, {}, Const.PROFILE[0])
+ self.presence.unavailableReceived(Const.JID[0], None)
def test_subscribedReceived(self):
- self.host.bridge.expectCall("subscribe", "subscribed", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
- self.presence.subscribedReceived(Const.TEST_JID)
+ self.host.bridge.expectCall("subscribe", "subscribed", Const.JID[0].userhost(), Const.PROFILE[0])
+ self.presence.subscribedReceived(Const.JID[0])
def test_unsubscribedReceived(self):
- self.host.bridge.expectCall("subscribe", "unsubscribed", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
- self.presence.unsubscribedReceived(Const.TEST_JID)
+ self.host.bridge.expectCall("subscribe", "unsubscribed", Const.JID[0].userhost(), Const.PROFILE[0])
+ self.presence.unsubscribedReceived(Const.JID[0])
def test_subscribeReceived(self):
- self.host.bridge.expectCall("subscribe", "subscribe", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
- self.presence.subscribeReceived(Const.TEST_JID)
+ self.host.bridge.expectCall("subscribe", "subscribe", Const.JID[0].userhost(), Const.PROFILE[0])
+ self.presence.subscribeReceived(Const.JID[0])
def test_unsubscribeReceived(self):
- self.host.bridge.expectCall("subscribe", "unsubscribe", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
- self.presence.unsubscribeReceived(Const.TEST_JID)
+ self.host.bridge.expectCall("subscribe", "unsubscribe", Const.JID[0].userhost(), Const.PROFILE[0])
+ self.presence.unsubscribeReceived(Const.JID[0])
diff --git a/src/test/test_plugin_xep_0033.py b/src/test/test_plugin_xep_0033.py
index fdb87df8..b0acae05 100644
--- a/src/test/test_plugin_xep_0033.py
+++ b/src/test/test_plugin_xep_0033.py
@@ -48,15 +48,15 @@ class XEP_0033Test(helpers.SatTestCase):
- """ % (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"""
content
- """ % (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()
diff --git a/src/test/test_plugin_xep_0085.py b/src/test/test_plugin_xep_0085.py
index b5b58600..258e0cf4 100644
--- a/src/test/test_plugin_xep_0085.py
+++ b/src/test/test_plugin_xep_0085.py
@@ -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"""
%s
<%s xmlns='%s'/>
- """ % (Const.TEST_JID_2_STR,
- Const.TEST_JID_STR,
+ """ % (Const.JID_STR[1],
+ Const.JID_STR[0],
"test" 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):
%s
- """ % (Const.TEST_JID_2_STR, Const.TEST_JID_STR,
+ """ % (Const.JID_STR[1], Const.JID_STR[0],
("%s" % 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"))