validator's function can have 1 arg, 2 args or 3 args
This commit is contained in:
parent
913a747a2e
commit
e2159fd307
4 changed files with 27 additions and 6 deletions
|
@ -212,6 +212,23 @@ def test_validator_params_value_values_kwargs_values():
|
||||||
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||||
|
|
||||||
|
|
||||||
|
def test_validator_params_value_values_kwargs2():
|
||||||
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||||
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||||
|
"masque du sous-reseau",
|
||||||
|
multi=True,
|
||||||
|
validator=value_values_index2,
|
||||||
|
validator_params={'': (['val1'],), 'index': ((ip_admin_eth0, False),)})
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
root = OptionDescription('root', '', [interface1])
|
||||||
|
cfg = Config(root)
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0[0] = 'val1'
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||||
|
|
||||||
|
|
||||||
def test_validator_params_value_values_kwargs_index():
|
def test_validator_params_value_values_kwargs_index():
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||||
|
|
|
@ -55,7 +55,7 @@ class PropertiesOptionError(AttributeError):
|
||||||
else:
|
else:
|
||||||
prop_msg = _('properties')
|
prop_msg = _('properties')
|
||||||
msg = display_list(msg)
|
msg = display_list(msg)
|
||||||
return _('cannot access to {0} "{1}" because has {2} {3}').format(self._type, self._datas['opt'].impl_get_display_name(), prop_msg, msg)
|
return str(_('cannot access to {0} "{1}" because has {2} {3}').format(self._type, self._datas['opt'].impl_get_display_name(), prop_msg, msg))
|
||||||
else:
|
else:
|
||||||
return super(PropertiesOptionError, self).__str__()
|
return super(PropertiesOptionError, self).__str__()
|
||||||
|
|
||||||
|
|
|
@ -175,13 +175,17 @@ class Base(StorageBase):
|
||||||
defaults = []
|
defaults = []
|
||||||
args = func_args.args[0:len(func_args.args)-len(defaults)]
|
args = func_args.args[0:len(func_args.args)-len(defaults)]
|
||||||
if validator_params is not None:
|
if validator_params is not None:
|
||||||
|
kwargs = validator_params.keys()
|
||||||
|
if '' in kwargs:
|
||||||
|
kwargs.remove('')
|
||||||
|
for kwarg in kwargs:
|
||||||
|
if kwarg in args:
|
||||||
|
args = args[0:args.index(kwarg)]
|
||||||
len_args = len(validator_params.get('', []))
|
len_args = len(validator_params.get('', []))
|
||||||
if len_args != 0 and len(args) <= len_args:
|
if len_args != 0 and len(args) >= len_args:
|
||||||
args = args[0:len(args)-len_args]
|
args = args[0:len(args)-len_args]
|
||||||
if len(args) >= 2:
|
if len(args) >= 2:
|
||||||
if validator_params is not None and args[1] in validator_params:
|
if validator_params is not None and '' in validator_params:
|
||||||
args = []
|
|
||||||
elif validator_params is not None and '' in validator_params:
|
|
||||||
params = list(validator_params[''])
|
params = list(validator_params[''])
|
||||||
params.append((self, False))
|
params.append((self, False))
|
||||||
validator_params[''] = tuple(params)
|
validator_params[''] = tuple(params)
|
||||||
|
|
|
@ -812,7 +812,7 @@ msgstr "la valeur default_multi est invalide {0} pour l'option {1} : {2}"
|
||||||
#: tiramisu/storage/dictionary/value.py:234
|
#: tiramisu/storage/dictionary/value.py:234
|
||||||
#: tiramisu/storage/sqlalchemy/option.py:666
|
#: tiramisu/storage/sqlalchemy/option.py:666
|
||||||
msgid "information's item not found: {0}"
|
msgid "information's item not found: {0}"
|
||||||
msgstr "aucune config spécifiée alors que c'est nécessaire"
|
msgstr "item '{0}' dans les informations non trouvée"
|
||||||
|
|
||||||
#: tiramisu/storage/dictionary/option.py:413
|
#: tiramisu/storage/dictionary/option.py:413
|
||||||
msgid "use impl_get_opt_by_path only with root OptionDescription"
|
msgid "use impl_get_opt_by_path only with root OptionDescription"
|
||||||
|
|
Loading…
Reference in a new issue