memory (params), test: fixes bug relative to parameter filtering
This commit is contained in:
parent
2a04d556a3
commit
900047c921
1 changed files with 63 additions and 6 deletions
|
|
@ -33,6 +33,12 @@ class MemoryTest(unittest.TestCase):
|
|||
self.host = helpers.FakeSAT()
|
||||
|
||||
def _getParamXML(self, param="1", security_level=None):
|
||||
"""Generate XML for testing parameters
|
||||
|
||||
@param param (str): parameter "1", "2" or "both"
|
||||
@param security_level: security level of the parameters
|
||||
@return (str)
|
||||
"""
|
||||
def getParam(name):
|
||||
return """
|
||||
<param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/>
|
||||
|
|
@ -61,7 +67,12 @@ class MemoryTest(unittest.TestCase):
|
|||
}
|
||||
|
||||
def _paramExists(self, param="1", src=None):
|
||||
"""@return: True is the param (category, name) exists"""
|
||||
"""
|
||||
|
||||
@param param (str): parameter "1" or "2"
|
||||
@param src (DOM element): the top-level element to look in
|
||||
@return: True is the param exists
|
||||
"""
|
||||
if param == "1":
|
||||
name = Const.ENABLE_UNIBOX_PARAM
|
||||
else:
|
||||
|
|
@ -84,8 +95,14 @@ class MemoryTest(unittest.TestCase):
|
|||
return False
|
||||
|
||||
def assertParam_generic(self, param="1", src=None, exists=True, deferred=False):
|
||||
"""
|
||||
@param param (str): parameter "1" or "2"
|
||||
@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
|
||||
"""
|
||||
msg = "Expected parameter not found!\n" if exists else "Unexpected parameter found!\n"
|
||||
if deferred == False:
|
||||
if deferred:
|
||||
# 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))
|
||||
|
|
@ -107,6 +124,12 @@ class MemoryTest(unittest.TestCase):
|
|||
self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), False, True)
|
||||
|
||||
def _getParams(self, security_limit, app='', profile_key='@NONE@'):
|
||||
"""Get the parameters accessible with the given security limit and application name.
|
||||
|
||||
@param security_limit (int): the security limit
|
||||
@param app (str): empty string or "libervia"
|
||||
@param profile_key
|
||||
"""
|
||||
if profile_key == '@NONE@':
|
||||
profile_key = '@DEFAULT@'
|
||||
return self.host.memory.getParams(security_limit, app, profile_key)
|
||||
|
|
@ -165,15 +188,20 @@ class MemoryTest(unittest.TestCase):
|
|||
self.host.memory.updateParams(params)
|
||||
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
|
||||
self._getParams(0).addCallback(self.assertParamNotExists_async)
|
||||
self._getParams(1).addCallback(self.assertParamExists_async)
|
||||
return self._getParams(1).addCallback(self.assertParamExists_async)
|
||||
|
||||
def test_paramsRegisterApp(self):
|
||||
|
||||
def register(*args):
|
||||
def register(xml, security_limit, app):
|
||||
"""
|
||||
@param xml: XML definition of the parameters to be added
|
||||
@param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure
|
||||
@param app: name of the frontend registering the parameters
|
||||
"""
|
||||
logger = getLogger()
|
||||
level = logger.getEffectiveLevel()
|
||||
logger.setLevel(INFO)
|
||||
self.host.memory.paramsRegisterApp(*args)
|
||||
self.host.memory.paramsRegisterApp(xml, security_limit, app)
|
||||
logger.setLevel(level)
|
||||
|
||||
# tests with no security level on the parameter (most secure)
|
||||
|
|
@ -212,6 +240,21 @@ class MemoryTest(unittest.TestCase):
|
|||
register(params, 1, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
|
||||
# tests with security level 1 and several parameters being registered
|
||||
params = self._getParamXML("both", security_level=1)
|
||||
self.host.memory.init()
|
||||
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assertParamExists("2")
|
||||
self.host.memory.init()
|
||||
register(params, 0, Const.APP_NAME)
|
||||
self.assertParamNotExists()
|
||||
self.assertParamNotExists("2")
|
||||
self.host.memory.init()
|
||||
register(params, 1, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assertParamExists("2")
|
||||
|
||||
def test_paramsRegisterApp_getParams(self):
|
||||
# test retrieving the parameter for a specific frontend
|
||||
self.host.memory.init()
|
||||
|
|
@ -220,3 +263,14 @@ class MemoryTest(unittest.TestCase):
|
|||
self._getParams(1, '').addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)
|
||||
|
||||
# the same with several parameters registered at the same time
|
||||
self.host.memory.init()
|
||||
params = self._getParamXML('both', 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")
|
||||
self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async)
|
||||
self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async, "2")
|
||||
self._getParams(5, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)
|
||||
return self._getParams(5, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async, "2")
|
||||
|
|
|
|||
Loading…
Reference in a new issue