Mercurial > libervia-backend
diff src/test/helpers.py @ 782:0e5807193721
test: added some tests for Memory
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 04 Jan 2014 17:16:40 +0100 |
parents | 80ab2b58e205 |
children | c3acc1298a2f |
line wrap: on
line diff
--- a/src/test/helpers.py Sat Jan 04 15:46:30 2014 +0100 +++ b/src/test/helpers.py Sat Jan 04 17:16:40 2014 +0100 @@ -24,7 +24,9 @@ from sat.memory.memory import Params from twisted.trial.unittest import FailTest from twisted.trial import unittest +from twisted.internet import defer from xml.etree import cElementTree as etree +from sat.core import exceptions import re @@ -96,14 +98,28 @@ def __init__(self, host, storage): Params.__init__(self, host, storage) - self.values = {} # naive simulation of values storage + self.params = {} # naive simulation of values storage def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'): - self.values.setdefault(category, {}) - self.values[category][name] = value + profile = self.getProfileName(profile_key) + self.params.setdefault(profile, {}) + self.params[profile_key][(category, name)] = value def getParamA(self, name, category, attr="value", profile_key='@NONE@'): - return self.values[category][name] + profile = self.getProfileName(profile_key) + return self.params[profile][(category, name)] + + def getProfileName(self, profile_key, return_profile_keys=False): + if profile_key == '@DEFAULT@': + return Const.TEST_PROFILE + elif profile_key == '@NONE@': + raise exceptions.ProfileNotSetError + else: + return profile_key + + def loadIndParams(self, profile, cache=None): + self.params[profile] = {} + return defer.succeed(None) class FakeMemory(object): @@ -118,11 +134,11 @@ """Tests that manipulate params and/or entities should re-initialise the memory first to not fake the result.""" self.params.load_default_params() - self.params.values.clear() + self.params.params.clear() self.entities_data = {} # naive simulation of entities - def getProfileName(self, profile_key): - return profile_key + def getProfileName(self, profile_key, return_profile_keys=False): + return self.params.getProfileName(profile_key, return_profile_keys) def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"): pass @@ -139,9 +155,16 @@ def delWaitingSub(self, contact_jid, profile_key): pass + def getParams(self, security_limit=Const.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'): + """profile_key is set to @DEFAULT@ to avoid specifying it always""" + return self.params.getParams(security_limit, app, profile_key='@DEFAULT@') + def updateParams(self, xml, security_limit=Const.SECURITY_LIMIT, app=''): self.params.updateParams(xml, security_limit, app) + def paramsRegisterApp(self, xml, security_limit=Const.NO_SECURITY_LIMIT, app=''): + return self.params.paramsRegisterApp(xml, security_limit, app) + def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'): self.params.setParam(name, value, category, security_limit, profile_key)