Mercurial > libervia-backend
comparison src/test/test_plugin_xep_0033.py @ 793:cb2db0d85029
test: silent info/warning that were polluting the output
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 10 Jan 2014 18:19:34 +0100 |
parents | 2136be5a44a8 |
children | 1fe00f0c9a91 |
comparison
equal
deleted
inserted
replaced
792:2136be5a44a8 | 793:cb2db0d85029 |
---|---|
27 from sat.core.sat_main import AbortSendMessage, MessageSentAndStored | 27 from sat.core.sat_main import AbortSendMessage, MessageSentAndStored |
28 from copy import deepcopy | 28 from copy import deepcopy |
29 from twisted.internet import defer | 29 from twisted.internet import defer |
30 from wokkel.generic import parseXml | 30 from wokkel.generic import parseXml |
31 from twisted.words.protocols.jabber.jid import JID | 31 from twisted.words.protocols.jabber.jid import JID |
32 import logging | |
32 | 33 |
33 | 34 |
34 class XEP_0033Test(helpers.SatTestCase): | 35 class XEP_0033Test(helpers.SatTestCase): |
35 | 36 |
36 def setUp(self): | 37 def setUp(self): |
106 stored = [] | 107 stored = [] |
107 cache = set() | 108 cache = set() |
108 for to_s in [addresses[1], addresses[3], addresses[5]]: | 109 for to_s in [addresses[1], addresses[3], addresses[5]]: |
109 to_jid = JID(to_s) | 110 to_jid = JID(to_s) |
110 host = JID(to_jid.host) | 111 host = JID(to_jid.host) |
112 logger = logging.getLogger() | |
113 level = logger.getEffectiveLevel() | |
114 logger.setLevel(logging.ERROR) # remove warning pollution | |
111 if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.PROFILE[0]): | 115 if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.PROFILE[0]): |
112 if host not in cache: | 116 if host not in cache: |
113 sent.append(host) | 117 sent.append(host) |
114 stored.append(host) | 118 stored.append(host) |
115 cache.add(host) | 119 cache.add(host) |
116 stored.append(to_jid) | 120 stored.append(to_jid) |
117 else: | 121 else: |
118 sent.append(to_jid) | 122 sent.append(to_jid) |
119 stored.append(to_jid) | 123 stored.append(to_jid) |
124 logger.setLevel(level) | |
120 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" | 125 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" |
121 self.assertEqualUnsortedList(self.host.sent_messages, sent, msg) | 126 self.assertEqualUnsortedList(self.host.sent_messages, sent, msg) |
122 self.assertEqualUnsortedList(self.host.stored_messages, stored, msg) | 127 self.assertEqualUnsortedList(self.host.stored_messages, stored, msg) |
128 | |
129 def trigger(treatments, data, *args): | |
130 logger = logging.getLogger() | |
131 level = logger.getEffectiveLevel() | |
132 logger.setLevel(logging.ERROR) # remove warning pollution | |
133 self.plugin.sendMessageTrigger(*args) | |
134 treatments.callback(data) | |
135 logger.setLevel(level) | |
123 | 136 |
124 # feature is not supported, abort the message | 137 # feature is not supported, abort the message |
125 self.host.memory.init() | 138 self.host.memory.init() |
126 treatments = defer.Deferred() | 139 treatments = defer.Deferred() |
127 data = deepcopy(mess_data) | 140 data = deepcopy(mess_data) |
128 self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0]) | 141 trigger(treatments, data, data, treatments, Const.PROFILE[0]) |
129 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage)) | 142 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage)) |
130 treatments.callback(data) | |
131 | 143 |
132 # feature is supported | 144 # feature is supported |
133 self.host.init() | 145 self.host.init() |
134 self.host.memory.init() | 146 self.host.memory.init() |
135 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) | 147 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) |
136 treatments = defer.Deferred() | 148 treatments = defer.Deferred() |
137 data = deepcopy(mess_data) | 149 data = deepcopy(mess_data) |
138 self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0]) | 150 trigger(treatments, data, data, treatments, Const.PROFILE[0]) |
139 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) | 151 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) |
140 treatments.callback(data) | |
141 checkSentAndStored() | 152 checkSentAndStored() |
142 | 153 |
143 # check that a wrong recipient entity is fixed by the backend | 154 # check that a wrong recipient entity is fixed by the backend |
144 self.host.init() | 155 self.host.init() |
145 self.host.memory.init() | 156 self.host.memory.init() |
146 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) | 157 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) |
147 treatments = defer.Deferred() | 158 treatments = defer.Deferred() |
148 data = deepcopy(mess_data) | 159 data = deepcopy(mess_data) |
149 data["to"] = Const.JID[0] | 160 data["to"] = Const.JID[0] |
150 self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0]) | 161 trigger(treatments, mess_data, data, treatments, Const.PROFILE[0]) |
151 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) | 162 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) |
152 treatments.callback(mess_data) | |
153 checkSentAndStored() | 163 checkSentAndStored() |