Merge branch 'feature/new_api' into feature/3.0

This commit is contained in:
Emmanuel Garette 2017-11-12 20:17:29 +01:00
commit a8d022b67f
4 changed files with 35 additions and 37 deletions

View File

@ -801,7 +801,7 @@ def make_api(options, multi):
if 'options' in collected:
options.extend(collected['options'])
for key, values in collected.items():
if key == 'options':
if key in ['options', 'properties']:
continue
option = make_optiondescriptions(key, values)
if option is None:
@ -817,9 +817,9 @@ def make_api(options, multi):
continue
local_collect_options = collect_options
for optiondescription in path.split('.')[:-1]:
local_collect_options.setdefault(optiondescription, {})
local_collect_options.setdefault(optiondescription, {'properties': {}})
local_collect_options = local_collect_options[optiondescription]
local_collect_options['properties'] = option.get(optiondescription, {})
local_collect_options['properties'].update(option.get(optiondescription, {}))
option_name = path.split('.')[-1]
path = '.'.join(path.split('.')[:-1])
local_collect_options.setdefault('options', []).append(make_option(option_name, option.get(option_name)))
@ -853,7 +853,7 @@ DICT_PATHS = [
('odmaster.second', {'second': {'disabled': True}}),
('odmaster.third', {'third': {'hidden': True}})]),
##test a config with dynoption
OrderedDict([('subod.firstv', {'subod': {'dyn': True}}),
OrderedDict([('subod.first', {'subod': {'dyn': True}}),
('subod.second', {'second': {'disabled': True}}),
('subod.third', {'third': {'hidden': True}}),
('subodval1.firstval1', None),
@ -863,7 +863,7 @@ DICT_PATHS = [
('subodval2.secondval2', None),
('subodval2.thirdval2', None)]),
#test a config with dynoption subdir
OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}}),
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True}}),
('subod.subsubod.second', {'second': {'disabled': True}}),
('subod.subsubod.third', {'third': {'hidden': True}}),
('subod.subsubodval1.firstval1', None),
@ -888,23 +888,24 @@ def test_options(paths):
api = make_api(paths, multi)
if api is None:
continue
check_all(api, lpaths[0], multi)
check_all(api, lpaths[1], multi, propertyerror=True, extra_properties=['disabled'])
check_all(api, lpaths[2], multi, permissive=True, extra_properties=['hidden'])
if len(lpaths) == 6:
if len(lpaths) == 9:
check_all(api, lpaths[3], multi)
check_all(api, lpaths[4], multi, propertyerror=True, extra_properties=['disabled'])
check_all(api, lpaths[5], multi, permissive=True, extra_properties=['hidden'])
##
#print('')
#print(api.help)
check_all(api, lpaths[6], multi)
check_all(api, lpaths[7], multi, propertyerror=True, extra_properties=['disabled'])
check_all(api, lpaths[8], multi, permissive=True, extra_properties=['hidden'])
else:
check_all(api, lpaths[0], multi)
check_all(api, lpaths[1], multi, propertyerror=True, extra_properties=['disabled'])
check_all(api, lpaths[2], multi, permissive=True, extra_properties=['hidden'])
DICT_PATHS2 = [
OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}),
('subod.subsubod.second', {}),
('subod.subsubod.third', {})]),
OrderedDict([('subod.subsubod.first', {'subsub': {'dyn': True, 'hidden': True}}),
OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True, 'hidden': True}}),
('subod.subsubod.second', {}),
('subod.subsubod.third', {}),
('subod.subsubodval1.firstval1', None),
@ -923,19 +924,22 @@ def paths2(request):
return request.param
#FIXME
#def test_tree_od_permissive(paths2):
# """permissive when optiondescription is hidden
# """
# lpaths = list(paths2.keys())
# for multi in (False, True):
# api = make_api(paths2, multi)
# if api is None:
# continue
# check_all(api, lpaths[0], multi, permissive=True)
# check_all(api, lpaths[1], multi, permissive=True)
# check_all(api, lpaths[2], multi, permissive=True, extra_properties=['hidden'])
# if len(lpaths) == 6:
# check_all(api, lpaths[3], multi, permissive=True)
# check_all(api, lpaths[4], multi, permissive=True)
# check_all(api, lpaths[5], multi, permissive=True, extra_properties=['hidden'])
def test_tree_od_permissive(paths2):
"""permissive when optiondescription is hidden
"""
lpaths = list(paths2.keys())
for multi in (False, True):
api = make_api(paths2, multi)
if api is None:
continue
if len(lpaths) == 9:
check_all(api, lpaths[3], multi, permissive=True)
check_all(api, lpaths[4], multi, permissive=True)
check_all(api, lpaths[5], multi, permissive=True)
check_all(api, lpaths[6], multi, permissive=True)
check_all(api, lpaths[7], multi, permissive=True)
check_all(api, lpaths[8], multi, permissive=True)
else:
check_all(api, lpaths[0], multi, permissive=True)
check_all(api, lpaths[1], multi, permissive=True)
check_all(api, lpaths[2], multi, permissive=True)

View File

@ -285,12 +285,6 @@ def test_values_with_master_remove():
assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.128']
def test_master_not_valid_name():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
raises(ValueError, "MasterSlaves('interface1', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_sub_group_in_master_group():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)

View File

@ -385,7 +385,7 @@ class TiramisuAPI(object):
def option(self, path, index=None):
validate = not self.force_unrestraint
settings = self.config.cfgimpl_get_settings()
setting_properties = settings.getcontextproperties()
setting_properties = settings.get_global_properties()
opt = self.config.unwrap_from_path(path,
setting_properties=setting_properties,
validate=validate,

View File

@ -369,7 +369,7 @@ class Settings(object):
return Property(self, properties, opt, path)
return properties
def getcontextproperties(self):
def get_global_properties(self):
return self._getproperties()
def __setitem__(self, opt, value): # pragma: optional cover