Mercurial > libervia-backend
changeset 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 | 52c4b755aba6 |
files | src/test/test_memory.py src/test/test_plugin_xep_0033.py |
diffstat | 2 files changed, 34 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/test/test_memory.py Thu Jan 09 11:18:33 2014 +0100 +++ b/src/test/test_memory.py Fri Jan 10 18:19:34 2014 +0100 @@ -21,6 +21,7 @@ from sat.test import helpers from twisted.trial import unittest import traceback +import logging from constants import Const from xml.dom import minidom @@ -135,38 +136,46 @@ self._getParams(1).addCallback(self.assertParamExists_async) def test_paramsRegisterApp(self): + + def register(*args): + logger = logging.getLogger() + level = logger.getEffectiveLevel() + logger.setLevel(logging.INFO) + self.host.memory.paramsRegisterApp(*args) + logger.setLevel(level) + # tests with no security level on the parameter (most secure) params = self._getParamXML() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) + register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, 0, Const.APP_NAME) + register(params, 0, Const.APP_NAME) self.assertParamNotExists() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME) + register(params, 1, Const.APP_NAME) self.assertParamNotExists() # tests with security level 0 on the parameter (not secure) params = self._getParamXML(security_level=0) self.host.memory.init() - self.host.memory.paramsRegisterApp(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) + register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, 0, Const.APP_NAME) + register(params, 0, Const.APP_NAME) self.assertParamExists() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME) + register(params, 1, Const.APP_NAME) self.assertParamExists() # tests with security level 1 on the parameter (more secure) params = self._getParamXML(security_level=1) self.host.memory.init() - self.host.memory.paramsRegisterApp(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) + register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, 0, Const.APP_NAME) + register(params, 0, Const.APP_NAME) self.assertParamNotExists() self.host.memory.init() - self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME) + register(params, 1, Const.APP_NAME) self.assertParamExists() def test_paramsRegisterApp_getParams(self):
--- a/src/test/test_plugin_xep_0033.py Thu Jan 09 11:18:33 2014 +0100 +++ b/src/test/test_plugin_xep_0033.py Fri Jan 10 18:19:34 2014 +0100 @@ -29,6 +29,7 @@ from twisted.internet import defer from wokkel.generic import parseXml from twisted.words.protocols.jabber.jid import JID +import logging class XEP_0033Test(helpers.SatTestCase): @@ -108,6 +109,9 @@ for to_s in [addresses[1], addresses[3], addresses[5]]: to_jid = JID(to_s) host = JID(to_jid.host) + logger = logging.getLogger() + level = logger.getEffectiveLevel() + logger.setLevel(logging.ERROR) # remove warning pollution if self.host.memory.hasServerFeature(plugin.NS_ADDRESS, host, Const.PROFILE[0]): if host not in cache: sent.append(host) @@ -117,17 +121,25 @@ else: sent.append(to_jid) stored.append(to_jid) + logger.setLevel(level) msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" self.assertEqualUnsortedList(self.host.sent_messages, sent, msg) self.assertEqualUnsortedList(self.host.stored_messages, stored, msg) + def trigger(treatments, data, *args): + logger = logging.getLogger() + level = logger.getEffectiveLevel() + logger.setLevel(logging.ERROR) # remove warning pollution + self.plugin.sendMessageTrigger(*args) + treatments.callback(data) + logger.setLevel(level) + # feature is not supported, abort the message self.host.memory.init() treatments = defer.Deferred() data = deepcopy(mess_data) - self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0]) + trigger(treatments, data, data, treatments, Const.PROFILE[0]) treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage)) - treatments.callback(data) # feature is supported self.host.init() @@ -135,9 +147,8 @@ 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.PROFILE[0]) + trigger(treatments, data, data, treatments, Const.PROFILE[0]) treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) - treatments.callback(data) checkSentAndStored() # check that a wrong recipient entity is fixed by the backend @@ -147,7 +158,6 @@ treatments = defer.Deferred() data = deepcopy(mess_data) data["to"] = Const.JID[0] - self.plugin.sendMessageTrigger(data, treatments, Const.PROFILE[0]) + trigger(treatments, mess_data, data, treatments, Const.PROFILE[0]) treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) - treatments.callback(mess_data) checkSentAndStored()