diff src/test/test_memory.py @ 1051:854880a31717

memory (params), test: fixes updateParams bug
author souliane <souliane@mailoo.org>
date Tue, 03 Jun 2014 17:10:12 +0200
parents de415d7984f7
children 2308f8405ffb
line wrap: on
line diff
--- a/src/test/test_memory.py	Tue Jun 03 15:10:51 2014 +0200
+++ b/src/test/test_memory.py	Tue Jun 03 17:10:12 2014 +0200
@@ -35,7 +35,7 @@
     def _getParamXML(self, param="1", security_level=None):
         """Generate XML for testing parameters
 
-        @param param (str): parameter "1", "2" or "both"
+        @param param (str): a subset of "123"
         @param security_level: security level of the parameters
         @return (str)
         """
@@ -46,12 +46,13 @@
                             '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)
+        params = ''
+        if "1" in param:
+            params += getParam(Const.ENABLE_UNIBOX_PARAM)
+        if "2" in param:
+            params += getParam(Const.PARAM_IN_QUOTES)
+        if "3" in param:
+            params += getParam("Dummy param")
         return """
         <params>
         <individual>
@@ -69,7 +70,7 @@
     def _paramExists(self, param="1", src=None):
         """
 
-        @param param (str): parameter "1" or "2"
+        @param param (str): a character in "12"
         @param src (DOM element): the top-level element to look in
         @return: True is the param exists
         """
@@ -96,7 +97,7 @@
 
     def assertParam_generic(self, param="1", src=None, exists=True, deferred=False):
         """
-        @param param (str): parameter "1" or "2"
+        @param param (str): a character in "12"
         @param src (DOM element): the top-level element to look in
         @param exists (boolean): True to assert the param exists, False to assert it doesn't
         @param deferred (boolean): True if this method is called from a Deferred callback
@@ -160,13 +161,19 @@
         self.host.memory.updateParams(self._getParamXML('1'))
         self.assertParamExists("1")
         self.assertParamNotExists("2")
-        self.host.memory.updateParams(self._getParamXML('both'))
+        self.host.memory.updateParams(self._getParamXML('12'))
         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"))
 
+        self.host.memory.init()
+        # one update with two params in a new category
+        self.host.memory.updateParams(self._getParamXML('12'))
+        self.assertParamExists("1")
+        self.assertParamExists("2")
+
     def test_getParams(self):
         # tests with no security level on the parameter (most secure)
         params = self._getParamXML()
@@ -241,7 +248,7 @@
         self.assertParamExists()
 
         # tests with security level 1 and several parameters being registered
-        params = self._getParamXML("both", security_level=1)
+        params = self._getParamXML("12", security_level=1)
         self.host.memory.init()
         register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
         self.assertParamExists()
@@ -255,6 +262,14 @@
         self.assertParamExists()
         self.assertParamExists("2")
 
+        # tests with several parameters being registered in an existing category
+        self.host.memory.init()
+        self.host.memory.updateParams(self._getParamXML("3"))
+        register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
+        self.assertParamExists()
+        self.assertParamExists("2")
+        self.host.memory.init()
+
     def test_paramsRegisterApp_getParams(self):
         # test retrieving the parameter for a specific frontend
         self.host.memory.init()
@@ -266,7 +281,7 @@
 
         # the same with several parameters registered at the same time
         self.host.memory.init()
-        params = self._getParamXML('both', security_level=0)
+        params = self._getParamXML('12', security_level=0)
         self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME)
         self._getParams(5, '').addCallback(self.assertParamExists_async)
         self._getParams(5, '').addCallback(self.assertParamExists_async, "2")