Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1050:de415d7984f7 | 1051:854880a31717 |
---|---|
33 self.host = helpers.FakeSAT() | 33 self.host = helpers.FakeSAT() |
34 | 34 |
35 def _getParamXML(self, param="1", security_level=None): | 35 def _getParamXML(self, param="1", security_level=None): |
36 """Generate XML for testing parameters | 36 """Generate XML for testing parameters |
37 | 37 |
38 @param param (str): parameter "1", "2" or "both" | 38 @param param (str): a subset of "123" |
39 @param security_level: security level of the parameters | 39 @param security_level: security level of the parameters |
40 @return (str) | 40 @return (str) |
41 """ | 41 """ |
42 def getParam(name): | 42 def getParam(name): |
43 return """ | 43 return """ |
44 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/> | 44 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/> |
45 """ % {'param_name': name, | 45 """ % {'param_name': name, |
46 'param_label': _(name), | 46 'param_label': _(name), |
47 'security': '' if security_level is None else ('security="%d"' % security_level) | 47 'security': '' if security_level is None else ('security="%d"' % security_level) |
48 } | 48 } |
49 if param == "1": | 49 params = '' |
50 params = getParam(Const.ENABLE_UNIBOX_PARAM) | 50 if "1" in param: |
51 elif param == "2": | 51 params += getParam(Const.ENABLE_UNIBOX_PARAM) |
52 params = getParam(Const.PARAM_IN_QUOTES) | 52 if "2" in param: |
53 else: | 53 params += getParam(Const.PARAM_IN_QUOTES) |
54 params = getParam(Const.ENABLE_UNIBOX_PARAM) + getParam(Const.PARAM_IN_QUOTES) | 54 if "3" in param: |
55 params += getParam("Dummy param") | |
55 return """ | 56 return """ |
56 <params> | 57 <params> |
57 <individual> | 58 <individual> |
58 <category name="%(category_name)s" label="%(category_label)s"> | 59 <category name="%(category_name)s" label="%(category_label)s"> |
59 %(params)s | 60 %(params)s |
67 } | 68 } |
68 | 69 |
69 def _paramExists(self, param="1", src=None): | 70 def _paramExists(self, param="1", src=None): |
70 """ | 71 """ |
71 | 72 |
72 @param param (str): parameter "1" or "2" | 73 @param param (str): a character in "12" |
73 @param src (DOM element): the top-level element to look in | 74 @param src (DOM element): the top-level element to look in |
74 @return: True is the param exists | 75 @return: True is the param exists |
75 """ | 76 """ |
76 if param == "1": | 77 if param == "1": |
77 name = Const.ENABLE_UNIBOX_PARAM | 78 name = Const.ENABLE_UNIBOX_PARAM |
94 return True | 95 return True |
95 return False | 96 return False |
96 | 97 |
97 def assertParam_generic(self, param="1", src=None, exists=True, deferred=False): | 98 def assertParam_generic(self, param="1", src=None, exists=True, deferred=False): |
98 """ | 99 """ |
99 @param param (str): parameter "1" or "2" | 100 @param param (str): a character in "12" |
100 @param src (DOM element): the top-level element to look in | 101 @param src (DOM element): the top-level element to look in |
101 @param exists (boolean): True to assert the param exists, False to assert it doesn't | 102 @param exists (boolean): True to assert the param exists, False to assert it doesn't |
102 @param deferred (boolean): True if this method is called from a Deferred callback | 103 @param deferred (boolean): True if this method is called from a Deferred callback |
103 """ | 104 """ |
104 msg = "Expected parameter not found!\n" if exists else "Unexpected parameter found!\n" | 105 msg = "Expected parameter not found!\n" if exists else "Unexpected parameter found!\n" |
158 self.host.memory.init() | 159 self.host.memory.init() |
159 # check successive updates (with intersection) | 160 # check successive updates (with intersection) |
160 self.host.memory.updateParams(self._getParamXML('1')) | 161 self.host.memory.updateParams(self._getParamXML('1')) |
161 self.assertParamExists("1") | 162 self.assertParamExists("1") |
162 self.assertParamNotExists("2") | 163 self.assertParamNotExists("2") |
163 self.host.memory.updateParams(self._getParamXML('both')) | 164 self.host.memory.updateParams(self._getParamXML('12')) |
164 self.assertParamExists("1") | 165 self.assertParamExists("1") |
165 self.assertParamExists("2") | 166 self.assertParamExists("2") |
166 | 167 |
167 # successive updates with or without intersection should have the same result | 168 # successive updates with or without intersection should have the same result |
168 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) | 169 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) |
170 | |
171 self.host.memory.init() | |
172 # one update with two params in a new category | |
173 self.host.memory.updateParams(self._getParamXML('12')) | |
174 self.assertParamExists("1") | |
175 self.assertParamExists("2") | |
169 | 176 |
170 def test_getParams(self): | 177 def test_getParams(self): |
171 # tests with no security level on the parameter (most secure) | 178 # tests with no security level on the parameter (most secure) |
172 params = self._getParamXML() | 179 params = self._getParamXML() |
173 self.host.memory.init() | 180 self.host.memory.init() |
239 self.host.memory.init() | 246 self.host.memory.init() |
240 register(params, 1, Const.APP_NAME) | 247 register(params, 1, Const.APP_NAME) |
241 self.assertParamExists() | 248 self.assertParamExists() |
242 | 249 |
243 # tests with security level 1 and several parameters being registered | 250 # tests with security level 1 and several parameters being registered |
244 params = self._getParamXML("both", security_level=1) | 251 params = self._getParamXML("12", security_level=1) |
245 self.host.memory.init() | 252 self.host.memory.init() |
246 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) | 253 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) |
247 self.assertParamExists() | 254 self.assertParamExists() |
248 self.assertParamExists("2") | 255 self.assertParamExists("2") |
249 self.host.memory.init() | 256 self.host.memory.init() |
252 self.assertParamNotExists("2") | 259 self.assertParamNotExists("2") |
253 self.host.memory.init() | 260 self.host.memory.init() |
254 register(params, 1, Const.APP_NAME) | 261 register(params, 1, Const.APP_NAME) |
255 self.assertParamExists() | 262 self.assertParamExists() |
256 self.assertParamExists("2") | 263 self.assertParamExists("2") |
264 | |
265 # tests with several parameters being registered in an existing category | |
266 self.host.memory.init() | |
267 self.host.memory.updateParams(self._getParamXML("3")) | |
268 register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME) | |
269 self.assertParamExists() | |
270 self.assertParamExists("2") | |
271 self.host.memory.init() | |
257 | 272 |
258 def test_paramsRegisterApp_getParams(self): | 273 def test_paramsRegisterApp_getParams(self): |
259 # test retrieving the parameter for a specific frontend | 274 # test retrieving the parameter for a specific frontend |
260 self.host.memory.init() | 275 self.host.memory.init() |
261 params = self._getParamXML(security_level=1) | 276 params = self._getParamXML(security_level=1) |
264 self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async) | 279 self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async) |
265 self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async) | 280 self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async) |
266 | 281 |
267 # the same with several parameters registered at the same time | 282 # the same with several parameters registered at the same time |
268 self.host.memory.init() | 283 self.host.memory.init() |
269 params = self._getParamXML('both', security_level=0) | 284 params = self._getParamXML('12', security_level=0) |
270 self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME) | 285 self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME) |
271 self._getParams(5, '').addCallback(self.assertParamExists_async) | 286 self._getParams(5, '').addCallback(self.assertParamExists_async) |
272 self._getParams(5, '').addCallback(self.assertParamExists_async, "2") | 287 self._getParams(5, '').addCallback(self.assertParamExists_async, "2") |
273 self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async) | 288 self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async) |
274 self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async, "2") | 289 self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async, "2") |