Mercurial > libervia-backend
comparison src/test/test_plugin_xep_0033.py @ 1909:0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 11 Mar 2016 16:41:44 +0100 |
parents | d17772b0fe22 |
children | 2daf7b4c6756 |
comparison
equal
deleted
inserted
replaced
1908:ffcd7904b655 | 1909:0681d69cbe0a |
---|---|
22 | 22 |
23 from constants import Const | 23 from constants import Const |
24 from sat.test import helpers | 24 from sat.test import helpers |
25 from sat.plugins import plugin_xep_0033 as plugin | 25 from sat.plugins import plugin_xep_0033 as plugin |
26 from sat.core.exceptions import CancelError | 26 from sat.core.exceptions import CancelError |
27 from sat.core.log import getLogger | |
28 from twisted.internet import defer | 27 from twisted.internet import defer |
29 from wokkel.generic import parseXml | 28 from wokkel.generic import parseXml |
30 from twisted.words.protocols.jabber.jid import JID | 29 from twisted.words.protocols.jabber.jid import JID |
31 from logging import ERROR | 30 from logging import ERROR |
32 | 31 |
106 /!\ see the comments in XEP_0033.sendAndStoreMessage""" | 105 /!\ see the comments in XEP_0033.sendAndStoreMessage""" |
107 sent = [] | 106 sent = [] |
108 stored = [] | 107 stored = [] |
109 d_list = [] | 108 d_list = [] |
110 | 109 |
111 def cb(entities, to_jid, logger, level): | 110 def cb(entities, to_jid): |
112 if host in entities: | 111 if host in entities: |
113 if host not in sent: # send the message to the entity offering the feature | 112 if host not in sent: # send the message to the entity offering the feature |
114 sent.append(host) | 113 sent.append(host) |
115 stored.append(host) | 114 stored.append(host) |
116 stored.append(to_jid) # store in history for each recipient | 115 stored.append(to_jid) # store in history for each recipient |
117 else: # feature not supported, use normal behavior | 116 else: # feature not supported, use normal behavior |
118 sent.append(to_jid) | 117 sent.append(to_jid) |
119 stored.append(to_jid) | 118 stored.append(to_jid) |
120 logger.setLevel(level) | 119 helpers.unmuteLogging() |
121 | 120 |
122 for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): | 121 for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): |
123 to_jid = JID(to_s) | 122 to_jid = JID(to_s) |
124 host = JID(to_jid.host) | 123 host = JID(to_jid.host) |
125 logger = getLogger() | 124 helpers.muteLogging() |
126 level = logger.getEffectiveLevel() | 125 d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile=PROFILE) |
127 logger.setLevel(ERROR) # remove log.warning pollution | 126 d.addCallback(cb, to_jid) |
128 d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile_key=PROFILE) | |
129 d.addCallback(cb, to_jid, logger, level) | |
130 d_list.append(d) | 127 d_list.append(d) |
131 | 128 |
132 def cb_list(dummy): | 129 def cb_list(dummy): |
133 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" | 130 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" |
134 sent_recipients = [JID(elt['to']) for elt in self.host.getSentMessages(PROFILE_INDEX)] | 131 sent_recipients = [JID(elt['to']) for elt in self.host.getSentMessages(PROFILE_INDEX)] |
142 level to not pollute the output, then check that the plugin did its | 139 level to not pollute the output, then check that the plugin did its |
143 job. It should abort sending the message or add the extended | 140 job. It should abort sending the message or add the extended |
144 addressing information to the stanza. | 141 addressing information to the stanza. |
145 @param data: the data to be processed by self.plugin.sendMessageTrigger | 142 @param data: the data to be processed by self.plugin.sendMessageTrigger |
146 """ | 143 """ |
147 logger = getLogger() | |
148 level = logger.getEffectiveLevel() | |
149 logger.setLevel(ERROR) # remove log.warning pollution | |
150 pre_treatments = defer.Deferred() | 144 pre_treatments = defer.Deferred() |
151 post_treatments = defer.Deferred() | 145 post_treatments = defer.Deferred() |
146 helpers.muteLogging() | |
152 self.plugin.sendMessageTrigger(data, pre_treatments, post_treatments, PROFILE) | 147 self.plugin.sendMessageTrigger(data, pre_treatments, post_treatments, PROFILE) |
153 post_treatments.callback(data) | 148 post_treatments.callback(data) |
154 logger.setLevel(level) | 149 helpers.unmuteLogging() |
155 post_treatments.addCallbacks(self._assertAddresses, lambda failure: failure.trap(CancelError)) | 150 post_treatments.addCallbacks(self._assertAddresses, lambda failure: failure.trap(CancelError)) |
156 return post_treatments | 151 return post_treatments |
157 | 152 |
158 def test_sendMessageTriggerFeatureNotSupported(self): | 153 def test_sendMessageTriggerFeatureNotSupported(self): |
159 # feature is not supported, abort the message | 154 # feature is not supported, abort the message |