diff src/test/test_plugin_xep_0033.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 0cb423500fbb
children cb2db0d85029
line wrap: on
line diff
--- a/src/test/test_plugin_xep_0033.py	Fri Jan 10 18:07:36 2014 +0100
+++ b/src/test/test_plugin_xep_0033.py	Thu Jan 09 11:18:33 2014 +0100
@@ -48,15 +48,15 @@
                 <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 @@
         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 @@
             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 @@
         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 @@
         # 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()