Mercurial > libervia-backend
changeset 833:9bac2fc74968
memory: bug fix to not register twice frontends parameters + added some tests for param update
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 07 Feb 2014 17:10:24 +0100 |
parents | c4b22aedb7d7 |
children | 2d901b7fa861 |
files | src/memory/memory.py src/test/constants.py src/test/helpers.py src/test/test_memory_memory.py |
diffstat | 4 files changed, 66 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/memory/memory.py Wed Feb 05 16:36:51 2014 +0100 +++ b/src/memory/memory.py Fri Feb 07 17:10:24 2014 +0100 @@ -296,7 +296,7 @@ return None def updateParams(self, xml, security_limit=NO_SECURITY_LIMIT, app=''): - """import xml in parameters, do nothing if the param already exist + """import xml in parameters, update if the param already exists If security_limit is specified and greater than -1, the parameters that have a security level greater than security_limit are skipped. @param xml: parameters in xml form @@ -339,7 +339,7 @@ tgt_parent.appendChild(child) else: if child.nodeName == "param": - # The child update an existing parameter, we replace the node + # The child updates an existing parameter, we replace the node tgt_parent.replaceChild(child, node) else: # the node already exists, we recurse 1 more level @@ -361,10 +361,11 @@ warning(_("Trying to register frontends parameters with no specified app: aborted")) return if not hasattr(self, "frontends_cache"): - self.frontends_cache = {} + self.frontends_cache = [] if app in self.frontends_cache: - warning(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app})) + debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app})) return + self.frontends_cache.append(app) self.updateParams(xml, security_limit, app) debug("Frontends parameters registered for %(app)s" % {'app': app})
--- a/src/test/constants.py Wed Feb 05 16:36:51 2014 +0100 +++ b/src/test/constants.py Fri Feb 07 17:10:24 2014 +0100 @@ -39,5 +39,6 @@ # To test frontend parameters APP_NAME = "dummy_frontend" - ENABLE_UNIBOX_KEY = D_("Composition") + COMPOSITION_KEY = D_("Composition") ENABLE_UNIBOX_PARAM = D_("Enable unibox") + PARAM_IN_QUOTES = D_("'Wysiwyg' edition")
--- a/src/test/helpers.py Wed Feb 05 16:36:51 2014 +0100 +++ b/src/test/helpers.py Fri Feb 07 17:10:24 2014 +0100 @@ -240,6 +240,7 @@ re-initialise the memory first to not fake the result.""" self.params.load_default_params() self.params.params.clear() + self.params.frontends_cache = [] self.entities_data = {} self.server_features = {}
--- a/src/test/test_memory_memory.py Wed Feb 05 16:36:51 2014 +0100 +++ b/src/test/test_memory_memory.py Fri Feb 07 17:10:24 2014 +0100 @@ -31,33 +31,41 @@ def setUp(self): self.host = helpers.FakeSAT() - def _getParamXML(self, name=None, category=None, security_level=None): - if not name: - name = Const.ENABLE_UNIBOX_PARAM - if not category: - category = Const.ENABLE_UNIBOX_KEY + def _getParamXML(self, param="1", security_level=None): + def getParam(name): + return """ + <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/> + """ % {'param_name': name, + 'param_label': _(name), + 'security': '' if security_level is None else ('security="%d"' % security_level) + } + if param == "1": + params = getParam(Const.ENABLE_UNIBOX_PARAM) + elif param == "2": + params = getParam(Const.PARAM_IN_QUOTES) + else: + params = getParam(Const.ENABLE_UNIBOX_PARAM) + getParam(Const.PARAM_IN_QUOTES) return """ <params> <individual> <category name="%(category_name)s" label="%(category_label)s"> - <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/> + %(params)s </category> </individual> </params> """ % { - 'category_name': category, - 'category_label': _(category), - 'param_name': name, - 'param_label': _(name), - 'security': '' if security_level is None else ('security="%d"' % security_level) + 'category_name': Const.COMPOSITION_KEY, + 'category_label': _(Const.COMPOSITION_KEY), + 'params': params } - def _paramExists(self, name=None, category=None, src=None): + def _paramExists(self, param="1", src=None): """@return: True is the param (category, name) exists""" - if not name: + if param == "1": name = Const.ENABLE_UNIBOX_PARAM - if not category: - category = Const.ENABLE_UNIBOX_KEY + else: + name = Const.PARAM_IN_QUOTES + category = Const.COMPOSITION_KEY if src is None: src = self.host.memory.params.dom.documentElement for type_node in src.childNodes: @@ -74,28 +82,28 @@ return True return False - def assertParam_generic(self, src=None, exists=True, deferred=False): + def assertParam_generic(self, param="1", src=None, exists=True, deferred=False): msg = "Expected parameter not found!\n" if exists else "Unexpected parameter found!\n" if deferred == False: # in this stack we can see the line where the error came from, # if limit=5, 6 is not enough you can increase the value msg += "\n".join(traceback.format_stack(limit=5 if exists else 6)) - assertion = self._paramExists(src=src) + assertion = self._paramExists(param, src) getattr(self, "assert%s" % exists)(assertion, msg) - def assertParamExists(self, src=None): - self.assertParam_generic(src, True) + def assertParamExists(self, param="1", src=None): + self.assertParam_generic(param, src, True) - def assertParamNotExists(self, src=None): - self.assertParam_generic(src, False) + def assertParamNotExists(self, param="1", src=None): + self.assertParam_generic(param, src, False) - def assertParamExists_async(self, src): + def assertParamExists_async(self, src, param="1"): """@param src: a deferred result from Memory.getParams""" - self.assertParam_generic(minidom.parseString(src.encode("utf-8")), True, True) + self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), True, True) - def assertParamNotExists_async(self, src): + def assertParamNotExists_async(self, src, param="1"): """@param src: a deferred result from Memory.getParams""" - self.assertParam_generic(minidom.parseString(src.encode("utf-8")), False, True) + self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), False, True) def _getParams(self, security_limit, app='', profile_key='@NONE@'): if profile_key == '@NONE@': @@ -112,6 +120,29 @@ self.host.memory.updateParams(self._getParamXML()) self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) + self.host.memory.init() + # check successive updates (without intersection) + self.host.memory.updateParams(self._getParamXML('1')) + self.assertParamExists("1") + self.assertParamNotExists("2") + self.host.memory.updateParams(self._getParamXML('2')) + self.assertParamExists("1") + self.assertParamExists("2") + + previous = self.host.memory.params.dom.cloneNode(True) # save for later + + self.host.memory.init() + # check successive updates (with intersection) + self.host.memory.updateParams(self._getParamXML('1')) + self.assertParamExists("1") + self.assertParamNotExists("2") + self.host.memory.updateParams(self._getParamXML('both')) + self.assertParamExists("1") + self.assertParamExists("2") + + # successive updates with or without intersection should have the same result + self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) + def test_getParams(self): # tests with no security level on the parameter (most secure) params = self._getParamXML() @@ -155,6 +186,7 @@ self.host.memory.init() 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() @@ -166,6 +198,7 @@ self.host.memory.init() 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()