comparison 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
comparison
equal deleted inserted replaced
791:23b0c949b86c 792:2136be5a44a8
46 <address type='to' jid='%s'/> 46 <address type='to' jid='%s'/>
47 <address type='cc' jid='%s'/> 47 <address type='cc' jid='%s'/>
48 <address type='bcc' jid='%s'/> 48 <address type='bcc' jid='%s'/>
49 </addresses> 49 </addresses>
50 </message> 50 </message>
51 """ % (Const.TEST_JID_2_STR, self.host.getClientHostJid(Const.TEST_PROFILE), 51 """ % (Const.JID_STR[1], self.host.getClientHostJid(Const.PROFILE[0]),
52 Const.TEST_JID_STR, Const.TEST_JID_2_STR, Const.TEST_JID_3_STR) 52 Const.JID_STR[0], Const.JID_STR[1], Const.JID_STR[2])
53 stanza = parseXml(xml.encode("utf-8")) 53 stanza = parseXml(xml.encode("utf-8"))
54 treatments = defer.Deferred() 54 treatments = defer.Deferred()
55 self.plugin.messageReceivedTrigger(stanza, treatments, Const.TEST_PROFILE) 55 self.plugin.messageReceivedTrigger(stanza, treatments, Const.PROFILE[0])
56 data = {'extra': {}} 56 data = {'extra': {}}
57 57
58 def cb(data): 58 def cb(data):
59 expected = ('to', Const.TEST_JID_STR, 'cc', Const.TEST_JID_2_STR, 'bcc', Const.TEST_JID_3_STR) 59 expected = ('to', Const.JID_STR[0], 'cc', Const.JID_STR[1], 'bcc', Const.JID_STR[2])
60 msg = 'Expected: %s\nGot: %s' % (expected, data['extra']['addresses']) 60 msg = 'Expected: %s\nGot: %s' % (expected, data['extra']['addresses'])
61 self.assertEqual(data['extra']['addresses'], '%s:%s\n%s:%s\n%s:%s\n' % expected, msg) 61 self.assertEqual(data['extra']['addresses'], '%s:%s\n%s:%s\n%s:%s\n' % expected, msg)
62 62
63 treatments.addCallback(cb) 63 treatments.addCallback(cb)
64 treatments.callback(data) 64 treatments.callback(data)
65 65
66 def test_sendMessageTrigger(self): 66 def test_sendMessageTrigger(self):
67 mess_data = {"to": self.host.getClientHostJid(Const.TEST_PROFILE), 67 mess_data = {"to": self.host.getClientHostJid(Const.PROFILE[0]),
68 "type": "chat", 68 "type": "chat",
69 "message": "content", 69 "message": "content",
70 "extra": {} 70 "extra": {}
71 } 71 }
72 addresses = ('to', Const.TEST_JID_STR, 'cc', Const.TEST_JID_2_STR, 'bcc', Const.TEST_JID_3_STR) 72 addresses = ('to', Const.JID_STR[0], 'cc', Const.JID_STR[1], 'bcc', Const.JID_STR[2])
73 mess_data["extra"]["address"] = '%s:%s\n%s:%s\n%s:%s\n' % addresses 73 mess_data["extra"]["address"] = '%s:%s\n%s:%s\n%s:%s\n' % addresses
74 original_stanza = u""" 74 original_stanza = u"""
75 <message type="chat" from="%s" to="%s" id="test_1"> 75 <message type="chat" from="%s" to="%s" id="test_1">
76 <body>content</body> 76 <body>content</body>
77 </message> 77 </message>
78 """ % (Const.TEST_JID_2_STR, self.host.getClientHostJid(Const.TEST_PROFILE)) 78 """ % (Const.JID_STR[1], self.host.getClientHostJid(Const.PROFILE[0]))
79 mess_data['xml'] = parseXml(original_stanza.encode("utf-8")) 79 mess_data['xml'] = parseXml(original_stanza.encode("utf-8"))
80 expected = deepcopy(mess_data['xml']) 80 expected = deepcopy(mess_data['xml'])
81 addresses_extra = """ 81 addresses_extra = """
82 <addresses xmlns='http://jabber.org/protocol/address'> 82 <addresses xmlns='http://jabber.org/protocol/address'>
83 <address type='%s' jid='%s'/> 83 <address type='%s' jid='%s'/>
106 stored = [] 106 stored = []
107 cache = set() 107 cache = set()
108 for to_s in [addresses[1], addresses[3], addresses[5]]: 108 for to_s in [addresses[1], addresses[3], addresses[5]]:
109 to_jid = JID(to_s) 109 to_jid = JID(to_s)
110 host = JID(to_jid.host) 110 host = JID(to_jid.host)
111 if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.TEST_PROFILE): 111 if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.PROFILE[0]):
112 if host not in cache: 112 if host not in cache:
113 sent.append(host) 113 sent.append(host)
114 stored.append(host) 114 stored.append(host)
115 cache.add(host) 115 cache.add(host)
116 stored.append(to_jid) 116 stored.append(to_jid)
123 123
124 # feature is not supported, abort the message 124 # feature is not supported, abort the message
125 self.host.memory.init() 125 self.host.memory.init()
126 treatments = defer.Deferred() 126 treatments = defer.Deferred()
127 data = deepcopy(mess_data) 127 data = deepcopy(mess_data)
128 self.plugin.sendMessageTrigger(data, treatments, Const.TEST_PROFILE) 128 self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0])
129 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage)) 129 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage))
130 treatments.callback(data) 130 treatments.callback(data)
131 131
132 # feature is supported 132 # feature is supported
133 self.host.init() 133 self.host.init()
134 self.host.memory.init() 134 self.host.memory.init()
135 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.TEST_PROFILE), Const.TEST_PROFILE) 135 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
136 treatments = defer.Deferred() 136 treatments = defer.Deferred()
137 data = deepcopy(mess_data) 137 data = deepcopy(mess_data)
138 self.plugin.sendMessageTrigger(data, treatments, Const.TEST_PROFILE) 138 self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0])
139 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) 139 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored))
140 treatments.callback(data) 140 treatments.callback(data)
141 checkSentAndStored() 141 checkSentAndStored()
142 142
143 # check that a wrong recipient entity is fixed by the backend 143 # check that a wrong recipient entity is fixed by the backend
144 self.host.init() 144 self.host.init()
145 self.host.memory.init() 145 self.host.memory.init()
146 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.TEST_PROFILE), Const.TEST_PROFILE) 146 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
147 treatments = defer.Deferred() 147 treatments = defer.Deferred()
148 data = deepcopy(mess_data) 148 data = deepcopy(mess_data)
149 data["to"] = Const.TEST_JID 149 data["to"] = Const.JID[0]
150 self.plugin.sendMessageTrigger(data, treatments, Const.TEST_PROFILE) 150 self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0])
151 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) 151 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored))
152 treatments.callback(mess_data) 152 treatments.callback(mess_data)
153 checkSentAndStored() 153 checkSentAndStored()