better hidden/display support
This commit is contained in:
parent
83f05197fb
commit
fb1286e50e
@ -370,7 +370,6 @@ def test_callback_value_tuple(config_type):
|
||||
|
||||
|
||||
def test_callback_value_force_permissive2(config_type):
|
||||
config_type = 'tiramisu-api'
|
||||
val1 = StrOption('val1', "", 'val', properties=('disabled',))
|
||||
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
|
||||
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
|
||||
@ -578,7 +577,7 @@ def test_callback_leader_and_followers_leader2(config_type):
|
||||
assert cfg.option('val1.val2', 0).value.get() == 'val2'
|
||||
|
||||
|
||||
def test_callback_leader_and_followers_leader_mandatory(config_type):
|
||||
def test_callback_leader_and_followers_leader_mandatory1(config_type):
|
||||
val = StrOption('val', "", default='val')
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
|
||||
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
|
||||
@ -591,9 +590,13 @@ def test_callback_leader_and_followers_leader_mandatory(config_type):
|
||||
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
||||
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
||||
assert cfg.option('val1.val1').value.get() == ['val']
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('val1.val1').value.set([undefined, 'val3'])
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.read_only()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('val1.val1').value.get() == ['val', 'val3']
|
||||
|
@ -162,7 +162,6 @@ def test_consistency_not_equal(config_type):
|
||||
|
||||
|
||||
def test_consistency_not_equal_many_opts(config_type):
|
||||
config_type='tiramisu-api'
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
@ -584,7 +583,6 @@ def test_consistency_ip_netmask_invalid():
|
||||
|
||||
|
||||
def test_consistency_network_netmask(config_type):
|
||||
config_type = 'tiramisu-api'
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
|
@ -2,6 +2,7 @@
|
||||
"frozen and hidden values"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from py.test import raises
|
||||
|
||||
@ -45,95 +46,122 @@ def make_description():
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
def test_is_hidden():
|
||||
def test_is_hidden(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
assert not 'frozen' in api.forcepermissive.option('gc.dummy').property.get()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
assert not 'frozen' in cfg.forcepermissive.option('gc.dummy').property.get()
|
||||
cfg = get_config(cfg, config_type)
|
||||
# setattr
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
||||
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get() == False")
|
||||
# getattr
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get()")
|
||||
|
||||
|
||||
def test_group_is_hidden():
|
||||
def test_group_is_hidden(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.option('gc').property.add('hidden')
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
||||
assert 'hidden' in api.forcepermissive.option('gc').property.get()
|
||||
raises(PropertiesOptionError, "api.option('gc.float').value.get()")
|
||||
cfg_ori = Config(descr)
|
||||
cfg_ori.property.read_write()
|
||||
cfg_ori.option('gc').property.add('hidden')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get()")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
assert 'hidden' in cfg_ori.forcepermissive.option('gc').property.get()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('gc.float').value.get()")
|
||||
# manually set the subconfigs to "show"
|
||||
api.forcepermissive.option('gc').property.pop('hidden')
|
||||
assert not 'hidden' in api.option('gc').property.get()
|
||||
assert api.option('gc.float').value.get() == 2.3
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.forcepermissive.option('gc').property.pop('hidden')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert not 'hidden' in cfg.option('gc').property.get()
|
||||
assert cfg.option('gc.float').value.get() == 2.3
|
||||
#dummy est en hide
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').value.set(False)
|
||||
cfg.option('gc.dummy').value.set(False)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'hidden' in prop
|
||||
if config_type == 'tiramisu-api':
|
||||
assert 'disabled' in prop
|
||||
else:
|
||||
assert 'hidden' in prop
|
||||
|
||||
|
||||
def test_group_is_hidden_multi():
|
||||
def test_group_is_hidden_multi(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.option('objspace').property.add('hidden')
|
||||
raises(PropertiesOptionError, "api.option('objspace').value.get()")
|
||||
assert 'hidden' in api.forcepermissive.option('objspace').property.get()
|
||||
cfg_ori = Config(descr)
|
||||
cfg_ori.property.read_write()
|
||||
cfg_ori.option('objspace').property.add('hidden')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('objspace').value.get()")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
assert 'hidden' in cfg_ori.forcepermissive.option('objspace').property.get()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
prop = []
|
||||
try:
|
||||
api.option('objspace').value.set(['std'])
|
||||
cfg.option('objspace').value.set(['std'])
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'hidden' in prop
|
||||
api.forcepermissive.option('objspace').property.pop('hidden')
|
||||
assert not 'hidden' in api.option('objspace').property.get()
|
||||
api.option('objspace').value.set(['std', 'std'])
|
||||
if config_type == 'tiramisu-api':
|
||||
assert 'disabled' in prop
|
||||
else:
|
||||
assert 'hidden' in prop
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.forcepermissive.option('objspace').property.pop('hidden')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert not 'hidden' in cfg.option('objspace').property.get()
|
||||
cfg.option('objspace').value.set(['std', 'std'])
|
||||
|
||||
|
||||
def test_global_show():
|
||||
def test_global_show(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.forcepermissive.option('gc.dummy').property.add('hidden')
|
||||
assert 'hidden' in api.forcepermissive.option('gc.dummy').property.get()
|
||||
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg.forcepermissive.option('gc.dummy').property.add('hidden')
|
||||
assert 'hidden' in cfg.forcepermissive.option('gc.dummy').property.get()
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get() == False")
|
||||
|
||||
|
||||
def test_with_many_subgroups():
|
||||
def test_with_many_subgroups(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
cfg_ori = Config(descr)
|
||||
#booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
|
||||
#setting = config.cfgimpl_get_settings()
|
||||
assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get()
|
||||
assert api.option('gc.subgroup.booltwo').value.get() is False
|
||||
api.option('gc.subgroup.booltwo').property.add('hidden')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert not 'hidden' in cfg.option('gc.subgroup.booltwo').property.get()
|
||||
assert cfg.option('gc.subgroup.booltwo').value.get() is False
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.option('gc.subgroup.booltwo').property.add('hidden')
|
||||
|
||||
|
||||
def test_password_option():
|
||||
def test_password_option(config_type):
|
||||
o = PasswordOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
api = Config(d)
|
||||
cfg = Config(d)
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('o').value.set('a_valid_password')
|
||||
raises(ValueError, "api.option('o').value.set(1)")
|
||||
cfg.option('o').value.set('a_valid_password')
|
||||
raises(ValueError, "cfg.option('o').value.set(1)")
|
||||
|
||||
|
||||
def test_date_option():
|
||||
def test_date_option(config_type):
|
||||
o = DateOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
api = Config(d)
|
||||
cfg = Config(d)
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('o').value.set('2017-02-04')
|
||||
api.option('o').value.set('2017-2-4')
|
||||
raises(ValueError, "api.option('o').value.set(1)")
|
||||
raises(ValueError, "api.option('o').value.set('2017-13-20')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-11-31')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-12-32')")
|
||||
raises(ValueError, "api.option('o').value.set('2017-2-29')")
|
||||
raises(ValueError, "api.option('o').value.set('2-2-2017')")
|
||||
raises(ValueError, "api.option('o').value.set('2017/2/2')")
|
||||
cfg.option('o').value.set('2017-02-04')
|
||||
cfg.option('o').value.set('2017-2-4')
|
||||
raises(ValueError, "cfg.option('o').value.set(1)")
|
||||
raises(ValueError, "cfg.option('o').value.set('2017-13-20')")
|
||||
raises(ValueError, "cfg.option('o').value.set('2017-11-31')")
|
||||
raises(ValueError, "cfg.option('o').value.set('2017-12-32')")
|
||||
raises(ValueError, "cfg.option('o').value.set('2017-2-29')")
|
||||
raises(ValueError, "cfg.option('o').value.set('2-2-2017')")
|
||||
raises(ValueError, "cfg.option('o').value.set('2017/2/2')")
|
||||
|
@ -1,5 +1,6 @@
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
import warnings
|
||||
from py.test import raises
|
||||
@ -39,9 +40,9 @@ def return_if_val(value):
|
||||
|
||||
|
||||
def is_context(value, context):
|
||||
api = Config(context)
|
||||
api.property.pop('validator')
|
||||
if not isinstance(api, Config):
|
||||
cfg = Config(context)
|
||||
cfg.property.pop('validator')
|
||||
if not isinstance(cfg, Config):
|
||||
raise ValueError('not context')
|
||||
|
||||
|
||||
@ -96,114 +97,130 @@ def value_empty(value, empty, values):
|
||||
|
||||
|
||||
def valid_from_config(value, config):
|
||||
api = Config(config)
|
||||
if api.option('opt1').value.get() != u'yes':
|
||||
cfg = Config(config)
|
||||
if cfg.option('opt1').value.get() != u'yes':
|
||||
raise ValueError("c'est une erreur")
|
||||
|
||||
|
||||
def test_validator():
|
||||
def test_validator(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val')
|
||||
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
|
||||
opt2 = StrOption('opt2', '', validator=return_false)
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('opt2').value.set('val')")
|
||||
cfg_ori = Config(root)
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "cfg.option('opt2').value.set('val')")
|
||||
try:
|
||||
api.option('opt2').value.set('val')
|
||||
cfg.option('opt2').value.set('val')
|
||||
except ValueError as err:
|
||||
msg = _('"{0}" is an invalid {1} for "{2}"').format('val', _('string'), 'opt2') + ', ' + _('test error return_false')
|
||||
assert str(err) == msg
|
||||
api.property.add('demoting_error_warning')
|
||||
if config_type == 'tiramisu-api':
|
||||
msg = _('"{0}" is an invalid {1} for "{2}"').format('val', 'string', 'opt2') + ', ' + _('test error return_false')
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('demoting_error_warning')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
cfg.option('opt2').value.set('val')
|
||||
assert len(w) == 1
|
||||
assert str(w[0].message) == msg
|
||||
|
||||
|
||||
def test_validator_params():
|
||||
def test_validator_params(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamValue('yes')), default='val')
|
||||
raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')")
|
||||
opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')))
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('opt2').value.set('val')")
|
||||
api.property.add('demoting_error_warning')
|
||||
cfg_ori = Config(root)
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
raises(ValueError, "cfg.option('opt2').value.set('val')")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('demoting_error_warning')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
cfg.option('opt2').value.set('val')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_validator_params_value_values():
|
||||
def test_validator_params_value_values(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
api.option('opt1').value.set(['val1', 'val2'])
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('opt1').value.get() == ['val']
|
||||
cfg.option('opt1').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_index():
|
||||
def test_validator_params_value_values_index(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
api.option('opt1').value.set(['val1', 'val2'])
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('opt1').value.get() == ['val']
|
||||
cfg.option('opt1').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_leader():
|
||||
def test_validator_params_value_values_leader(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_index_leader():
|
||||
def test_validator_params_value_values_index_leader(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_follower():
|
||||
def test_validator_params_value_values_follower(config_type):
|
||||
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)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_index_follower():
|
||||
def test_validator_params_value_values_index_follower(config_type):
|
||||
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_index)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_notmulti():
|
||||
raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')")
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_empty():
|
||||
def test_validator_params_value_values_kwargs_empty(config_type):
|
||||
v = BoolOption('v', '', default=False)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
@ -213,14 +230,15 @@ def test_validator_params_value_values_kwargs_empty():
|
||||
validator_params=Params(ParamOption(v)))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [v, interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
#cfg.ip_admin_eth0.ip_admin_eth0.append('val')
|
||||
#cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs():
|
||||
def test_validator_params_value_values_kwargs(config_type):
|
||||
v = BoolOption('v', '', default=False)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
@ -230,14 +248,15 @@ def test_validator_params_value_values_kwargs():
|
||||
validator_params=Params(kwargs={'auto': ParamOption(v)}))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [v, interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_values():
|
||||
def test_validator_params_value_values_kwargs_values(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
@ -246,15 +265,16 @@ def test_validator_params_value_values_kwargs_values():
|
||||
validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)}))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs2():
|
||||
def test_validator_params_value_values_kwargs2(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
@ -263,14 +283,15 @@ def test_validator_params_value_values_kwargs2():
|
||||
validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)}))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
|
||||
|
||||
def test_validator_params_value_values_kwargs_index():
|
||||
def test_validator_params_value_values_kwargs_index(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
@ -279,158 +300,181 @@ def test_validator_params_value_values_kwargs_index():
|
||||
validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)}))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
|
||||
|
||||
|
||||
def test_validator_params_context():
|
||||
opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val')
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = Config(root)
|
||||
assert 'validator' in api.property.get()
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
assert 'validator' in api.property.get()
|
||||
cfg = Config(root)
|
||||
# cfg = get_config(cfg, config_type) # ParamContext not supported
|
||||
assert 'validator' in cfg.property.get()
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
assert 'validator' in cfg.property.get()
|
||||
|
||||
|
||||
def test_validator_params_context_value():
|
||||
opt1 = StrOption('opt1', '', 'yes')
|
||||
opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val')
|
||||
root = OptionDescription('root', '', [opt1, opt2])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == 'yes'
|
||||
assert api.option('opt2').value.get() == 'val'
|
||||
api.option('opt1').value.set('no')
|
||||
raises(ValueError, "assert api.option('opt2').value.get()")
|
||||
api.property.add('demoting_error_warning')
|
||||
cfg = Config(root)
|
||||
# cfg = get_config(cfg_ori, config_type) # ParamContext not supported
|
||||
assert cfg.option('opt1').value.get() == 'yes'
|
||||
assert cfg.option('opt2').value.get() == 'val'
|
||||
cfg.option('opt1').value.set('no')
|
||||
raises(ValueError, "assert cfg.option('opt2').value.get()")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg.property.add('demoting_error_warning')
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.get()
|
||||
cfg.option('opt2').value.get()
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_validator_params_key():
|
||||
def test_validator_params_key(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val')
|
||||
raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')")
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
|
||||
|
||||
def test_validator_params_option():
|
||||
def test_validator_params_option(config_type):
|
||||
opt0 = StrOption('opt0', '', default='yes')
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val')
|
||||
r = OptionDescription('root', '', [opt0, opt1])
|
||||
api = Config(r)
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
api.option('opt0').value.set('val')
|
||||
raises(ValueError, "api.option('opt1').value.get()")
|
||||
api.property.add('demoting_error_warning')
|
||||
cfg_ori = Config(r)
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
cfg.option('opt0').value.set('val')
|
||||
raises(ValueError, "cfg.option('opt1').value.get()")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('demoting_error_warning')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt1').value.get()
|
||||
cfg.option('opt1').value.get()
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_validator_multi():
|
||||
def test_validator_multi(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=return_if_val, multi=True)
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == []
|
||||
api.option('opt1').value.set(['val'])
|
||||
assert api.option('opt1').value.get() == ['val']
|
||||
raises(ValueError, "api.option('opt1').value.set(['val', 'val1'])")
|
||||
api.property.add('demoting_error_warning')
|
||||
cfg_ori = Config(root)
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('opt1').value.get() == []
|
||||
cfg.option('opt1').value.set(['val'])
|
||||
assert cfg.option('opt1').value.get() == ['val']
|
||||
raises(ValueError, "cfg.option('opt1').value.set(['val', 'val1'])")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('demoting_error_warning')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt1').value.set(['val', 'val1'])
|
||||
cfg.option('opt1').value.set(['val', 'val1'])
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_validator_warning():
|
||||
def test_validator_warning(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
|
||||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
api = Config(root)
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt1').value.set('val')
|
||||
cfg.option('opt1').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
cfg.option('opt2').value.set('val')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt() == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val'])
|
||||
cfg.option('opt3').value.set(['val'])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
cfg.option('opt3').value.set(['val', 'val1'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt() == opt3
|
||||
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == opt3
|
||||
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
raises(ValueError, "api.option('opt2').value.set(1)")
|
||||
raises(ValueError, "cfg.option('opt2').value.set(1)")
|
||||
assert len(w) == 0
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
cfg.option('opt2').value.set('val')
|
||||
cfg.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert len(w) == 2
|
||||
assert w[0].message.opt() == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
||||
assert w[1].message.opt() == opt3
|
||||
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
|
||||
assert w[1].message.opt() == opt3
|
||||
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
|
||||
|
||||
|
||||
def test_validator_warning_disabled():
|
||||
def test_validator_warning_disabled(config_type):
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
|
||||
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
|
||||
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
|
||||
root = OptionDescription('root', '', [opt1, opt2, opt3])
|
||||
api = Config(root)
|
||||
api.property.pop('warnings')
|
||||
assert api.option('opt1').value.get() == 'val'
|
||||
cfg_ori = Config(root)
|
||||
cfg_ori.property.pop('warnings')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('opt1').value.get() == 'val'
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt1').value.set('val')
|
||||
cfg.option('opt1').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
cfg.option('opt2').value.set('val')
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val'])
|
||||
cfg.option('opt3').value.set(['val'])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
cfg.option('opt3').value.set(['val', 'val1'])
|
||||
assert w == []
|
||||
raises(ValueError, "api.option('opt2').value.set(1)")
|
||||
raises(ValueError, "cfg.option('opt2').value.set(1)")
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
cfg.option('opt2').value.set('val')
|
||||
cfg.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert w == []
|
||||
#
|
||||
api.property.add('demoting_error_warning')
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set(1)
|
||||
assert len(w) == 1
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('demoting_error_warning')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
if config_type != 'tiramisu-api':
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.option('opt2').value.set(1)
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_validator_warning_leadership():
|
||||
def test_validator_warning_leadership(config_type):
|
||||
display_name_ip = "ip reseau autorise"
|
||||
display_name_netmask = "masque du sous-reseau"
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True)
|
||||
@ -438,48 +482,55 @@ def test_validator_warning_leadership():
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
assert interface1.impl_get_group_type() == groups.leadership
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
|
||||
assert w == []
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt() == netmask_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error'
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == netmask_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error'
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
else:
|
||||
assert len(w) == 2
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
else:
|
||||
assert len(w) == 3
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
else:
|
||||
assert len(w) == 3
|
||||
#
|
||||
warnings.resetwarnings()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
|
||||
if config_type != 'tiramisu-api':
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
|
||||
else:
|
||||
assert len(w) == 3
|
||||
|
||||
|
||||
def test_validator_follower_param():
|
||||
def test_validator_follower_param(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0',
|
||||
"masque du sous-reseau",
|
||||
@ -488,12 +539,13 @@ def test_validator_follower_param():
|
||||
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
root = OptionDescription('root', '', [interface1])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val')
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val')
|
||||
cfg = Config(root)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val')
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes'])
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val')
|
||||
|
||||
|
||||
def test_validator_dependencies():
|
||||
@ -504,11 +556,11 @@ def test_validator_dependencies():
|
||||
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
|
||||
opt2 = StrOption('opt2', '', validator=return_false)
|
||||
root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2])
|
||||
api = Config(root)
|
||||
assert api.option('ip_admin_eth0').option.has_dependency() is False
|
||||
assert api.option('netmask_admin_eth0').option.has_dependency() is True
|
||||
assert api.option('opt2').option.has_dependency() is False
|
||||
cfg = Config(root)
|
||||
assert cfg.option('ip_admin_eth0').option.has_dependency() is False
|
||||
assert cfg.option('netmask_admin_eth0').option.has_dependency() is True
|
||||
assert cfg.option('opt2').option.has_dependency() is False
|
||||
#
|
||||
assert api.option('ip_admin_eth0').option.has_dependency(False) is True
|
||||
assert api.option('netmask_admin_eth0').option.has_dependency(False) is False
|
||||
assert api.option('opt2').option.has_dependency(False) is False
|
||||
assert cfg.option('ip_admin_eth0').option.has_dependency(False) is True
|
||||
assert cfg.option('netmask_admin_eth0').option.has_dependency(False) is False
|
||||
assert cfg.option('opt2').option.has_dependency(False) is False
|
||||
|
@ -1,6 +1,7 @@
|
||||
#this test is much more to test that **it's there** and answers attribute access
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from py.test import raises
|
||||
|
||||
@ -36,17 +37,18 @@ def make_description():
|
||||
return descr
|
||||
|
||||
|
||||
def test_root_config_answers_ok():
|
||||
def test_root_config_answers_ok(config_type):
|
||||
"if you hide the root config, the options in this namespace behave normally"
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
|
||||
api = Config(descr)
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
#settings = cfg.cfgimpl_get_settings()
|
||||
#settings.append('hidden')
|
||||
|
||||
assert api.option('dummy').value.get() is False
|
||||
assert api.option('boolop').value.get() is True
|
||||
assert cfg.option('dummy').value.get() is False
|
||||
assert cfg.option('boolop').value.get() is True
|
||||
|
||||
|
||||
#def test_optname_shall_not_start_with_numbers():
|
||||
@ -54,9 +56,10 @@ def test_root_config_answers_ok():
|
||||
# raises(ValueError, "descr = OptionDescription('123tiramisu', '', [])")
|
||||
#
|
||||
#
|
||||
def test_option_has_an_api_name():
|
||||
def test_option_has_an_api_name(config_type):
|
||||
b = BoolOption('impl_has_dependency', 'dummy', default=True)
|
||||
descr = OptionDescription('tiramisu', '', [b])
|
||||
api = Config(descr)
|
||||
assert api.option('impl_has_dependency').value.get() is True
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('impl_has_dependency').value.get() is True
|
||||
assert b.impl_has_dependency() is False
|
||||
|
@ -1,12 +1,12 @@
|
||||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
from tiramisu.storage import list_sessions, delete_session
|
||||
|
||||
|
||||
@ -20,61 +20,81 @@ def make_description():
|
||||
return OptionDescription('od1', '', [u1, u2])
|
||||
|
||||
|
||||
def test_permissive():
|
||||
def test_permissive(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.property.read_write()
|
||||
cfg_ori = Config(descr)
|
||||
cfg_ori.property.read_write()
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
api.unrestraint.permissive.set(frozenset(['disabled']))
|
||||
assert api.unrestraint.permissive.get() == frozenset(['disabled'])
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.permissive.set(frozenset(['disabled']))
|
||||
assert cfg_ori.unrestraint.permissive.get() == frozenset(['disabled'])
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('permissive')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('u1').value.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.pop('permissive')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_permissive_add():
|
||||
def test_permissive_add(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.property.read_write()
|
||||
cfg_ori = Config(descr)
|
||||
cfg_ori.property.read_write()
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
api.unrestraint.permissive.add('disabled')
|
||||
assert api.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.permissive.add('disabled')
|
||||
assert cfg_ori.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('permissive')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('u1').value.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.pop('permissive')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
@ -82,22 +102,22 @@ def test_permissive_add():
|
||||
|
||||
def test_permissive_pop():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.property.read_write()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg.property.read_write()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.forcepermissive.option('u1').value.get()
|
||||
cfg.forcepermissive.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
api.unrestraint.permissive.add('disabled')
|
||||
assert api.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
|
||||
api.forcepermissive.option('u1').value.get()
|
||||
api.unrestraint.permissive.pop('disabled')
|
||||
cfg.unrestraint.permissive.add('disabled')
|
||||
assert cfg.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
|
||||
cfg.forcepermissive.option('u1').value.get()
|
||||
cfg.unrestraint.permissive.pop('disabled')
|
||||
props = frozenset()
|
||||
try:
|
||||
api.forcepermissive.option('u1').value.get()
|
||||
cfg.forcepermissive.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
@ -105,140 +125,138 @@ def test_permissive_pop():
|
||||
|
||||
def test_permissive_reset():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
assert api.unrestraint.permissive.get() == frozenset(['hidden'])
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
assert cfg.unrestraint.permissive.get() == frozenset(['hidden'])
|
||||
#
|
||||
api.unrestraint.permissive.set(frozenset(['disabled']))
|
||||
assert api.unrestraint.permissive.get() == frozenset(['disabled'])
|
||||
cfg.unrestraint.permissive.set(frozenset(['disabled']))
|
||||
assert cfg.unrestraint.permissive.get() == frozenset(['disabled'])
|
||||
#
|
||||
api.unrestraint.permissive.reset()
|
||||
assert api.unrestraint.permissive.get() == frozenset()
|
||||
cfg.unrestraint.permissive.reset()
|
||||
assert cfg.unrestraint.permissive.get() == frozenset()
|
||||
|
||||
|
||||
def test_permissive_mandatory():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_only()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_only()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
assert api.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
assert cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
|
||||
cfg.property.add('permissive')
|
||||
cfg.option('u1').value.get()
|
||||
cfg.property.pop('permissive')
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_permissive_frozen():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
|
||||
assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
|
||||
assert api.permissive.get() == frozenset(['frozen', 'disabled'])
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
|
||||
assert cfg.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
|
||||
assert cfg.permissive.get() == frozenset(['frozen', 'disabled'])
|
||||
try:
|
||||
api.option('u1').value.set(1)
|
||||
cfg.option('u1').value.set(1)
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'frozen'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.set(1)
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.pop('permissive')
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.property.add('permissive')
|
||||
cfg.option('u1').value.set(1)
|
||||
assert cfg.option('u1').value.get() == 1
|
||||
cfg.property.pop('permissive')
|
||||
try:
|
||||
api.option('u1').value.set(1)
|
||||
cfg.option('u1').value.set(1)
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'frozen'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_invalid_permissive():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])")
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
raises(TypeError, "cfg.unrestraint.permissive.set(['frozen', 'disabled'])")
|
||||
|
||||
|
||||
def test_forbidden_permissive():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.permissive.set(frozenset(['force_default_on_freeze']))")
|
||||
raises(ConfigError, "api.permissive.set(frozenset(['force_metaconfig_on_freeze']))")
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
raises(ConfigError, "cfg.permissive.set(frozenset(['force_default_on_freeze']))")
|
||||
raises(ConfigError, "cfg.permissive.set(frozenset(['force_metaconfig_on_freeze']))")
|
||||
|
||||
|
||||
def test_permissive_option():
|
||||
def test_permissive_option(config_type):
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
cfg_ori = Config(descr)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.add('permissive')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('u1').value.get()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.property.pop('permissive')
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.property.pop('permissive')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
@ -246,55 +264,55 @@ def test_permissive_option():
|
||||
|
||||
def test_permissive_option_cache():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
|
||||
cfg.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
cfg.property.add('permissive')
|
||||
cfg.option('u1').value.get()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.property.pop('permissive')
|
||||
cfg.property.pop('permissive')
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u2').value.get()
|
||||
cfg.option('u2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled'}
|
||||
@ -302,78 +320,85 @@ def test_permissive_option_cache():
|
||||
|
||||
def test_permissive_option_mandatory():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_only()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_only()
|
||||
props = frozenset()
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
assert api.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
|
||||
api.property.add('permissive')
|
||||
api.option('u1').value.get()
|
||||
api.property.pop('permissive')
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
|
||||
assert cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
|
||||
cfg.property.add('permissive')
|
||||
cfg.option('u1').value.get()
|
||||
cfg.property.pop('permissive')
|
||||
try:
|
||||
api.option('u1').value.get()
|
||||
cfg.option('u1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_permissive_option_frozen():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
|
||||
api.option('u1').value.set(1)
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.add('permissive')
|
||||
assert api.option('u1').value.get() == 1
|
||||
api.property.pop('permissive')
|
||||
assert api.option('u1').value.get() == 1
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
|
||||
cfg.option('u1').value.set(1)
|
||||
assert cfg.option('u1').value.get() == 1
|
||||
cfg.property.add('permissive')
|
||||
assert cfg.option('u1').value.get() == 1
|
||||
cfg.property.pop('permissive')
|
||||
assert cfg.option('u1').value.get() == 1
|
||||
|
||||
|
||||
if TIRAMISU_VERSION == 3:
|
||||
def test_invalid_option_permissive():
|
||||
descr = make_description()
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
|
||||
def test_invalid_option_permissive():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
raises(TypeError, "cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
|
||||
|
||||
|
||||
def test_remove_option_permissive():
|
||||
def test_remove_option_permissive(config_type):
|
||||
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
|
||||
od1 = OptionDescription('od1', '', [var1])
|
||||
rootod = OptionDescription('rootod', '', [od1])
|
||||
api = Config(rootod)
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
|
||||
assert api.option('od1.var1').value.get() == 'value'
|
||||
api.forcepermissive.option('od1.var1').permissive.set(frozenset())
|
||||
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset()
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
cfg_ori = Config(rootod)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
|
||||
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('od1.var1').value.get() == 'value'
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset())
|
||||
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
|
||||
|
||||
|
||||
def test_reset_option_permissive():
|
||||
def test_reset_option_permissive(config_type):
|
||||
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
|
||||
od1 = OptionDescription('od1', '', [var1])
|
||||
rootod = OptionDescription('rootod', '', [od1])
|
||||
api = Config(rootod)
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
|
||||
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
|
||||
assert api.option('od1.var1').value.get() == 'value'
|
||||
api.forcepermissive.option('od1.var1').permissive.reset()
|
||||
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset()
|
||||
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
||||
cfg_ori = Config(rootod)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
|
||||
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
assert cfg.option('od1.var1').value.get() == 'value'
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.forcepermissive.option('od1.var1').permissive.reset()
|
||||
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
|
||||
|
@ -1,6 +1,7 @@
|
||||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from copy import copy
|
||||
from tiramisu.i18n import _
|
||||
@ -9,7 +10,7 @@ from tiramisu import setting
|
||||
setting.expires_time = 1
|
||||
from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \
|
||||
Leadership, Config, calc_value, Params, ParamOption
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError, ConfigError
|
||||
from py.test import raises
|
||||
from tiramisu.storage import list_sessions, delete_session
|
||||
|
||||
@ -18,133 +19,147 @@ def teardown_function(function):
|
||||
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
||||
|
||||
|
||||
def test_properties():
|
||||
def test_properties(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '', properties=('disabled',))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg_ori = Config(od)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
api.option('ip_address_service').value.get()
|
||||
api.unrestraint.option('ip_address_service').property.add('disabled')
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.add('disabled')
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
# pop twice
|
||||
api.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
api.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
|
||||
|
||||
def test_requires():
|
||||
def test_requires(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
assert not api.option('activate_service').option.requires()
|
||||
assert api.option('ip_address_service').option.requires()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
assert not cfg.option('activate_service').option.requires()
|
||||
assert cfg.option('ip_address_service').option.requires()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_callback():
|
||||
def test_requires_callback(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
assert not api.option('activate_service').option.requires()
|
||||
assert api.option('ip_address_service').option.requires()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
assert not cfg.option('activate_service').option.requires()
|
||||
assert cfg.option('ip_address_service').option.requires()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_inverse():
|
||||
def test_requires_inverse(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(True)
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_self():
|
||||
def test_requires_self(config_type):
|
||||
a = StrOption('ip_address_service', '',
|
||||
requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
api.option('ip_address_service').value.set('a')
|
||||
assert api.option('ip_address_service').value.get() == 'a'
|
||||
api.option('ip_address_service').value.set('b')
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_address_service').value.get() == None
|
||||
cfg.option('ip_address_service').value.set('a')
|
||||
assert cfg.option('ip_address_service').value.get() == 'a'
|
||||
cfg.option('ip_address_service').value.set('b')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_with_requires():
|
||||
def test_requires_with_requires(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').property.add('test')
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg.option('ip_address_service').property.add('test')
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_invalid():
|
||||
@ -162,7 +177,7 @@ def test_requires_invalid():
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_requires_same_action():
|
||||
def test_requires_same_action(config_type):
|
||||
activate_service = BoolOption('activate_service', '', True)
|
||||
activate_service_web = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': activate_service, 'expected': False,
|
||||
@ -173,34 +188,42 @@ def test_requires_same_action():
|
||||
'action': 'disabled', 'inverse': False,
|
||||
'transitive': True, 'same_action': False}])
|
||||
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
|
||||
api = Config(od1)
|
||||
api.property.read_write()
|
||||
api.property.add('new')
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
cfg.property.add('new')
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['new'])
|
||||
if config_type == 'tiramisu':
|
||||
assert frozenset(props) == frozenset(['new'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
#access to cache
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
if config_type == 'tiramisu':
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
#access to cache
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
else:
|
||||
# FIXME
|
||||
assert str(err) == 'error'
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_same_action_callback():
|
||||
def test_requires_same_action_callback(config_type):
|
||||
activate_service = BoolOption('activate_service', '', True)
|
||||
activate_service_web = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate_service)), 'expected': False,
|
||||
@ -211,151 +234,175 @@ def test_requires_same_action_callback():
|
||||
'action': 'disabled', 'inverse': False,
|
||||
'transitive': True, 'same_action': False}])
|
||||
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
|
||||
api = Config(od1)
|
||||
api.property.read_write()
|
||||
api.property.add('new')
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
cfg.property.add('new')
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['new'])
|
||||
if config_type == 'tiramisu':
|
||||
assert frozenset(props) == frozenset(['new'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
submsg = '"disabled" (' + _('the calculated value is {0}').format('"False"') + ')'
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
#access to cache
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
if config_type == 'tiramisu':
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
#access to cache
|
||||
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
|
||||
else:
|
||||
# FIXME
|
||||
assert str(err) == 'error'
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_multiple_requires():
|
||||
def test_multiple_requires(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
{'option': a, 'expected': 'ok', 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set('yes')
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('yes')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('no')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative():
|
||||
def test_multiple_requires_cumulative(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
{'option': a, 'expected': 'yes', 'action': 'hidden'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
api.option('activate_service').value.set('yes')
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('yes')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('no')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative_inverse():
|
||||
def test_multiple_requires_cumulative_inverse(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
||||
{'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
api.option('activate_service').value.set('yes')
|
||||
api.option('ip_address_service').value.get()
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
cfg.option('activate_service').value.set('yes')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
cfg.option('activate_service').value.set('no')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_multiple_requires_inverse():
|
||||
def test_multiple_requires_inverse(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
||||
{'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set('yes')
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('yes')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('ok')
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set('no')
|
||||
cfg.option('activate_service').value.set('no')
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive():
|
||||
def test_requires_transitive(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -363,29 +410,30 @@ def test_requires_transitive():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_callback():
|
||||
def test_requires_transitive_callback(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}])
|
||||
@ -393,29 +441,30 @@ def test_requires_transitive_callback():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_unrestraint():
|
||||
def test_requires_transitive_unrestraint(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -423,18 +472,21 @@ def test_requires_transitive_unrestraint():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg_ori = Config(od)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
assert api.unrestraint.option('activate_service_web').property.get() == {'disabled'}
|
||||
assert api.unrestraint.option('ip_address_service_web').property.get() == {'disabled'}
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
assert cfg_ori.unrestraint.option('activate_service_web').property.get() == {'disabled'}
|
||||
assert cfg_ori.unrestraint.option('ip_address_service_web').property.get() == {'disabled'}
|
||||
|
||||
|
||||
def test_requires_transitive_owner():
|
||||
def test_requires_transitive_owner(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -442,23 +494,24 @@ def test_requires_transitive_owner():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
#no more default value
|
||||
api.option('ip_address_service_web').value.set('1.1.1.1')
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service_web').value.set('1.1.1.1')
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_bis():
|
||||
def test_requires_transitive_bis(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
abis = BoolOption('activate_service_bis', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
@ -467,23 +520,24 @@ def test_requires_transitive_bis():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, abis, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
#
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
@ -496,40 +550,45 @@ def test_requires_transitive_hidden_permissive():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
# FIXME permissive cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled():
|
||||
def test_requires_transitive_hidden_disabled(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['hidden'])
|
||||
api.option('ip_address_service_web').value.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['hidden'])
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled_multiple():
|
||||
def test_requires_transitive_hidden_disabled_multiple(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'},
|
||||
@ -537,41 +596,62 @@ def test_requires_transitive_hidden_disabled_multiple():
|
||||
d = IPOption('ip_address_service_web', '',
|
||||
requires=[{'option': b, 'expected': False, 'action': 'mandatory'}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == {'disabled', 'hidden'}
|
||||
del props
|
||||
#
|
||||
cfg_ori = Config(od)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
req = None
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
except RequirementError as err:
|
||||
req = err
|
||||
if config_type == 'tiramisu-api':
|
||||
try:
|
||||
cfg.option('activate_service').value.set(False)
|
||||
except ConfigError as err:
|
||||
req = err
|
||||
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"')))
|
||||
else:
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if config_type == 'tiramisu-api':
|
||||
assert set(props) == {'disabled',}
|
||||
else:
|
||||
assert set(props) == {'disabled', 'hidden'}
|
||||
del props
|
||||
#
|
||||
try:
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except RequirementError as err:
|
||||
req = err
|
||||
error_msg = str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"'))
|
||||
assert req, "ip_address_service_web should raise RequirementError"
|
||||
assert str(req) == str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"'))
|
||||
assert str(req) == error_msg
|
||||
del req
|
||||
#
|
||||
api.permissive.set(frozenset())
|
||||
try:
|
||||
api.option('ip_address_service_web').value.get()
|
||||
except RequirementError as err:
|
||||
req = err
|
||||
cfg_ori.permissive.set(frozenset())
|
||||
if config_type == 'tiramisu-api':
|
||||
try:
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
except ConfigError as err:
|
||||
req = err
|
||||
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and')))))
|
||||
else:
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
try:
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except RequirementError as err:
|
||||
req = err
|
||||
error_msg = str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and'))))
|
||||
assert req, "ip_address_service_web should raise RequirementError"
|
||||
assert str(req) == str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and'))))
|
||||
assert str(req) == error_msg
|
||||
del req
|
||||
|
||||
|
||||
def test_requires_not_transitive():
|
||||
def test_requires_not_transitive(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -579,24 +659,25 @@ def test_requires_not_transitive():
|
||||
requires=[{'option': b, 'expected': False,
|
||||
'action': 'disabled', 'transitive': False}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
api.option('ip_address_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_not_transitive_not_same_action():
|
||||
def test_requires_not_transitive_not_same_action(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -604,154 +685,162 @@ def test_requires_not_transitive_not_same_action():
|
||||
requires=[{'option': b, 'expected': False,
|
||||
'action': 'hidden', 'transitive': False}])
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('activate_service').value.get()
|
||||
api.option('activate_service_web').value.get()
|
||||
api.option('ip_address_service_web').value.get()
|
||||
api.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
raises(RequirementError, "api.option('ip_address_service_web').value.get()")
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('activate_service').value.get()
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
raises(ConfigError, "cfg.option('activate_service').value.set(False)")
|
||||
else:
|
||||
cfg.option('activate_service').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
raises(RequirementError, "cfg.option('ip_address_service_web').value.get()")
|
||||
|
||||
|
||||
def test_requires_None():
|
||||
def test_requires_None(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled():
|
||||
def test_requires_multi_disabled(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': True, 'action': 'disabled'},
|
||||
{'option': b, 'expected': 1, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_callback():
|
||||
def test_requires_multi_disabled_callback(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': True, 'action': 'disabled'},
|
||||
{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': 1, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format():
|
||||
def test_requires_multi_disabled_new_format(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
@ -781,84 +870,92 @@ def test_requires_unvalid():
|
||||
'action': 'disabled', 'operator': 'and'}])""")
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format_and():
|
||||
def test_requires_multi_disabled_new_format_and(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format_and_2():
|
||||
def test_requires_multi_disabled_new_format_and_2(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'},
|
||||
{'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = Config(od)
|
||||
api.property.add('expert')
|
||||
api.property.read_write()
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg = Config(od)
|
||||
cfg.property.add('expert')
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == []
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
api.option('num_service').value.set(1)
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['expert'])
|
||||
if config_type == 'tiramisu-api':
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['expert'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled', 'expert'])
|
||||
if config_type == 'tiramisu-api':
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled', 'expert'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse():
|
||||
def test_requires_multi_disabled_inverse(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -867,45 +964,46 @@ def test_requires_multi_disabled_inverse():
|
||||
{'option': b, 'expected': 1,
|
||||
'action': 'disabled', 'inverse': True}])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('num_service').value.set(1)
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
api.option('activate_service').value.set(True)
|
||||
api.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled_2():
|
||||
def test_requires_multi_disabled_2(config_type):
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
@ -927,32 +1025,33 @@ def test_requires_multi_disabled_2():
|
||||
y = copy(list_bools)
|
||||
y.append(z)
|
||||
od = OptionDescription('service', '', y)
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(True)
|
||||
cfg.option(boo.impl_getname()).value.set(True)
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(False)
|
||||
cfg.option(boo.impl_getname()).value.set(False)
|
||||
if boo == m:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
else:
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse_2():
|
||||
def test_requires_multi_disabled_inverse_2(config_type):
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
@ -975,93 +1074,106 @@ def test_requires_multi_disabled_inverse_2():
|
||||
y = copy(list_bools)
|
||||
y.append(z)
|
||||
od = OptionDescription('service', '', y)
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(True)
|
||||
cfg.option(boo.impl_getname()).value.set(True)
|
||||
if boo == m:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
else:
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
api.option(boo.impl_getname()).value.set(False)
|
||||
cfg.option(boo.impl_getname()).value.set(False)
|
||||
props = []
|
||||
try:
|
||||
api.option('z').value.get()
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_requirement_append():
|
||||
def test_requires_requirement_append(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.property.get()
|
||||
api.option('ip_address_service').property.get()
|
||||
raises(ValueError, "api.option('ip_address_service').property.add('disabled')")
|
||||
api.option('activate_service').value.set(False)
|
||||
cfg_ori = Config(od)
|
||||
cfg_ori.property.read_write()
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.property.get()
|
||||
cfg.option('ip_address_service').property.get()
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
raises(ValueError, "cfg_ori.option('ip_address_service').property.add('disabled')")
|
||||
cfg = get_config(cfg_ori, config_type)
|
||||
cfg.option('activate_service').value.set(False)
|
||||
# disabled is now set, test to remove disabled before store in storage
|
||||
api.unrestraint.option('ip_address_service').property.add("test")
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.add("test")
|
||||
|
||||
|
||||
def test_requires_different_inverse():
|
||||
def test_requires_different_inverse(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '', requires=[
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
api.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
cfg.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
|
||||
|
||||
def test_requires_different_inverse_unicode():
|
||||
def test_requires_different_inverse_unicode(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
d = StrOption('activate_other_service', '', 'val2')
|
||||
b = IPOption('ip_address_service', '', requires=[
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
|
||||
{'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}])
|
||||
od = OptionDescription('service', '', [a, d, b])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
api.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
api.option('activate_service').value.set(True)
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
api.option('activate_other_service').value.set('val1')
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
api.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()")
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_address_service').value.get() == None
|
||||
cfg.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
cfg.option('activate_service').value.set(True)
|
||||
assert cfg.option('ip_address_service').value.get() == None
|
||||
cfg.option('activate_other_service').value.set('val1')
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
cfg.option('activate_service').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
|
||||
|
||||
def test_requires_recursive_path():
|
||||
def test_requires_recursive_path(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('base', '', [od1])
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
raises(RequirementError, "api.option('service.a').value.get()")
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
if config_type == 'tiramisu-api':
|
||||
raises(ConfigError, "get_config(cfg, config_type)")
|
||||
else:
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(RequirementError, "cfg.option('service.a').value.get()")
|
||||
|
||||
|
||||
def test_optiondescription_requires():
|
||||
@ -1085,35 +1197,36 @@ def test_properties_conflict():
|
||||
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_leadership_requires():
|
||||
def test_leadership_requires(config_type):
|
||||
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,
|
||||
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
od = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
|
||||
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
ret = api.value.dict()
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
|
||||
@ -1123,8 +1236,8 @@ def test_leadership_requires():
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
ret = api.value.dict()
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
|
||||
@ -1135,35 +1248,36 @@ def test_leadership_requires():
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_leadership_requires_callback():
|
||||
def test_leadership_requires_callback(config_type):
|
||||
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,
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(ip_admin_eth0)), 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
od = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
|
||||
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
ret = api.value.dict()
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
|
||||
@ -1173,8 +1287,8 @@ def test_leadership_requires_callback():
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
ret = api.value.dict()
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
|
||||
@ -1219,174 +1333,183 @@ def test_leadership_requires_properties():
|
||||
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
|
||||
|
||||
def test_leadership_requires_leader():
|
||||
def test_leadership_requires_leader(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
|
||||
#
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert api.value.dict() == {'activate': False}
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_leader_callback():
|
||||
def test_leadership_requires_leader_callback(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
#
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert api.value.dict() == {'activate': False}
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_leadership():
|
||||
def test_leadership_requires_leadership(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
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)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
|
||||
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
#
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert api.value.dict() == {'activate': False}
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_leadership_callback():
|
||||
def test_leadership_requires_leadership_callback(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
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)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
#
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
#
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert api.value.dict() == {'activate': False}
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_no_leader():
|
||||
def test_leadership_requires_no_leader(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
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,
|
||||
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
api.option('activate').value.set(False)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False}
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
cfg.option('activate').value.set(False)
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
print('=======================================')
|
||||
print(cfg.value.dict())
|
||||
print({'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False})
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_no_leader_callback():
|
||||
def test_leadership_requires_no_leader_callback(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
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,
|
||||
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||
api = Config(maconfig)
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
api.option('activate').value.set(False)
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
api.option('activate').value.set(True)
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
api.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
dico = api.value.dict()
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
||||
cfg.option('activate').value.set(False)
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
cfg.option('activate').value.set(False)
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
|
||||
dico = cfg.value.dict()
|
||||
assert set(dico.keys()) == {'activate', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'}
|
||||
dico['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
dico['activate'] == False
|
||||
@ -1394,8 +1517,8 @@ def test_leadership_requires_no_leader_callback():
|
||||
del dico['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
|
||||
|
||||
def test_leadership_requires_complet():
|
||||
optiontoto = StrOption('unicodetoto', "Unicode leader")
|
||||
def test_leadership_requires_complet(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Unicode")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True)
|
||||
@ -1436,11 +1559,12 @@ def test_leadership_requires_complet():
|
||||
[option, option1, option2, option3, option4, option5, option6, option7])
|
||||
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
|
||||
descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr])
|
||||
config = Config(descr)
|
||||
config.property.read_write()
|
||||
config.option('options.unicode.unicode').value.set(['test', 'trah'])
|
||||
config.option('options.unicode.unicode2', 0).value.set('test')
|
||||
dico = config.value.dict()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
|
||||
cfg.option('options.unicode.unicode2', 0).value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'])
|
||||
assert dico['options.unicode.unicode'] == ['test', 'trah']
|
||||
assert dico['options.unicode.unicode1'] == [None, None]
|
||||
@ -1455,8 +1579,8 @@ def test_leadership_requires_complet():
|
||||
del dico['options.unicode.unicode4'][1]
|
||||
del dico['options.unicode.unicode4']
|
||||
#
|
||||
config.option('options.unicodetoto').value.set('test')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicodetoto').value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
|
||||
assert dico['options.unicode.unicode'] == ['test', 'trah']
|
||||
assert dico['options.unicode.unicode1'] == [None, None]
|
||||
@ -1481,7 +1605,7 @@ def test_leadership_requires_complet():
|
||||
del dico['options.unicode.unicode7']
|
||||
|
||||
|
||||
def test_leadership_requires_complet_callback():
|
||||
def test_leadership_requires_complet_callback(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Unicode leader")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
@ -1530,11 +1654,12 @@ def test_leadership_requires_complet_callback():
|
||||
[option, option1, option2, option3, option4, option5, option6, option7])
|
||||
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
|
||||
descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr])
|
||||
config = Config(descr)
|
||||
config.property.read_write()
|
||||
config.option('options.unicode.unicode').value.set(['test', 'trah'])
|
||||
config.option('options.unicode.unicode2', 0).value.set('test')
|
||||
dico = config.value.dict()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
|
||||
cfg.option('options.unicode.unicode2', 0).value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
|
||||
assert dico['options.unicode.unicode'] == ['test', 'trah']
|
||||
assert dico['options.unicode.unicode1'] == [None, None]
|
||||
@ -1555,8 +1680,8 @@ def test_leadership_requires_complet_callback():
|
||||
del dico['options.unicode.unicode7'][0]
|
||||
del dico['options.unicode.unicode7'][0]
|
||||
#
|
||||
config.option('options.unicodetoto').value.set('test')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicodetoto').value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
|
||||
assert dico['options.unicode.unicode'] == ['test', 'trah']
|
||||
assert dico['options.unicode.unicode1'] == [None, None]
|
||||
@ -1581,8 +1706,8 @@ def test_leadership_requires_complet_callback():
|
||||
del dico['options.unicode.unicode7']
|
||||
|
||||
|
||||
def test_leadership_requires_transitive():
|
||||
optiontoto = StrOption('unicodetoto', "Unicode leader")
|
||||
def test_leadership_requires_transitive1(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Simple unicode")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
option2 = StrOption('unicode2', "Unicode follower 2", requires=[{'option': optiontoto,
|
||||
@ -1607,15 +1732,16 @@ def test_leadership_requires_transitive():
|
||||
[option, option1, option2, option3, option4])
|
||||
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
|
||||
descr = OptionDescription("unicode1", "", [descr])
|
||||
config = Config(descr)
|
||||
config.property.read_write()
|
||||
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
|
||||
#
|
||||
config.option('options.unicodetoto').value.set('test')
|
||||
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
|
||||
cfg.option('options.unicodetoto').value.set('test')
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
|
||||
#
|
||||
config.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1634,9 +1760,9 @@ def test_leadership_requires_transitive():
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
config.option('options.unicode.unicode2', 1).value.set('test')
|
||||
config.option('options.unicode.unicode3', 1).value.set('test')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('test')
|
||||
cfg.option('options.unicode.unicode3', 1).value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1655,8 +1781,8 @@ def test_leadership_requires_transitive():
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
config.option('options.unicode.unicode2', 1).value.set('rah')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('rah')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1675,9 +1801,9 @@ def test_leadership_requires_transitive():
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
config.option('options.unicode.unicode2', 1).value.set('test')
|
||||
config.option('options.unicodetoto').value.set('rah')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('test')
|
||||
cfg.option('options.unicodetoto').value.set('rah')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'rah'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1696,7 +1822,7 @@ def test_leadership_requires_transitive():
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
|
||||
|
||||
def test_leadership_requires_transitive_callback():
|
||||
def test_leadership_requires_transitive_callback(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Unicode leader")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
@ -1725,15 +1851,16 @@ def test_leadership_requires_transitive_callback():
|
||||
[option, option1, option2, option3, option4])
|
||||
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
|
||||
descr = OptionDescription("unicode1", "", [descr])
|
||||
config = Config(descr)
|
||||
config.property.read_write()
|
||||
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
|
||||
#
|
||||
config.option('options.unicodetoto').value.set('test')
|
||||
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
|
||||
cfg.option('options.unicodetoto').value.set('test')
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
|
||||
#
|
||||
config.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1752,9 +1879,9 @@ def test_leadership_requires_transitive_callback():
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
config.option('options.unicode.unicode2', 1).value.set('test')
|
||||
config.option('options.unicode.unicode3', 1).value.set('test')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('test')
|
||||
cfg.option('options.unicode.unicode3', 1).value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1773,8 +1900,8 @@ def test_leadership_requires_transitive_callback():
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
config.option('options.unicode.unicode2', 1).value.set('rah')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('rah')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
@ -1793,9 +1920,9 @@ def test_leadership_requires_transitive_callback():
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
config.option('options.unicode.unicode2', 1).value.set('test')
|
||||
config.option('options.unicodetoto').value.set('rah')
|
||||
dico = config.value.dict()
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('test')
|
||||
cfg.option('options.unicodetoto').value.set('rah')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'rah'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
|
@ -2,12 +2,12 @@
|
||||
from py.test import raises
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from tiramisu import BoolOption, StrOption, SymLinkOption, \
|
||||
OptionDescription, Leadership, Config
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
from tiramisu.storage import list_sessions
|
||||
|
||||
|
||||
@ -20,52 +20,55 @@ def return_value():
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_symlink_option():
|
||||
def test_symlink_option(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
api.option("s1.b").value.set(True)
|
||||
api.option("s1.b").value.set(False)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
assert api.option('c').value.get() is False
|
||||
api.option('s1.b').value.set(True)
|
||||
assert api.option('s1.b').value.get() is True
|
||||
assert api.option('c').value.get() is True
|
||||
api.option('s1.b').value.set(False)
|
||||
assert api.option('s1.b').value.get() is False
|
||||
assert api.option('c').value.get() is False
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('s1.b').value.get() is False
|
||||
cfg.option("s1.b").value.set(True)
|
||||
cfg.option("s1.b").value.set(False)
|
||||
assert cfg.option('s1.b').value.get() is False
|
||||
assert cfg.option('c').value.get() is False
|
||||
cfg.option('s1.b').value.set(True)
|
||||
assert cfg.option('s1.b').value.get() is True
|
||||
assert cfg.option('c').value.get() is True
|
||||
cfg.option('s1.b').value.set(False)
|
||||
assert cfg.option('s1.b').value.get() is False
|
||||
assert cfg.option('c').value.get() is False
|
||||
|
||||
|
||||
def test_symlink_assign_option():
|
||||
def test_symlink_assign_option(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
raises(ConfigError, "api.option('c').value.set(True)")
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(ConfigError, "cfg.option('c').value.set(True)")
|
||||
|
||||
|
||||
def test_symlink_del_option():
|
||||
def test_symlink_del_option(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
raises(TypeError, "api.option('c').value.reset()")
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(ConfigError, "cfg.option('c').value.reset()")
|
||||
|
||||
|
||||
def test_symlink_addproperties():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.option('c').property.add('new')")
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
raises(TypeError, "cfg.option('c').property.add('new')")
|
||||
try:
|
||||
api.option('c').property.reset()
|
||||
cfg.option('c').property.reset()
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
@ -76,21 +79,21 @@ def test_symlink_getpermissive():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
api.option('b').permissive.set(frozenset(['perm']))
|
||||
api.option('c').permissive.get() == frozenset(['perm'])
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg.option('b').permissive.set(frozenset(['perm']))
|
||||
cfg.option('c').permissive.get() == frozenset(['perm'])
|
||||
|
||||
|
||||
def test_symlink_addpermissives():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
raises(TypeError, "api.option('c').permissive.set(frozenset(['new']))")
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
raises(TypeError, "cfg.option('c').permissive.set(frozenset(['new']))")
|
||||
try:
|
||||
api.option('c').permissive.reset()
|
||||
cfg.option('c').permissive.reset()
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
@ -101,12 +104,9 @@ def test_symlink_getproperties():
|
||||
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
|
||||
else:
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
|
||||
|
||||
|
||||
@ -114,89 +114,86 @@ def test_symlink_getcallback():
|
||||
boolopt = BoolOption('b', '', callback=return_value)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
|
||||
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None)
|
||||
|
||||
|
||||
def test_symlink_requires():
|
||||
def test_symlink_requires(config_type):
|
||||
boolopt = BoolOption('b', '', default=True)
|
||||
stropt = StrOption('s', '', requires=[{'option': boolopt,
|
||||
'expected': False,
|
||||
'action': 'disabled'}])
|
||||
linkopt = SymLinkOption("c", stropt)
|
||||
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
assert api.option('b').value.get() is True
|
||||
assert api.option('s').value.get() is None
|
||||
assert api.option('c').value.get() is None
|
||||
api.option('b').value.set(False)
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('b').value.get() is True
|
||||
assert cfg.option('s').value.get() is None
|
||||
assert cfg.option('c').value.get() is None
|
||||
cfg.option('b').value.set(False)
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('s').value.get()
|
||||
cfg.option('s').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert props == ['disabled']
|
||||
else:
|
||||
assert props == {'disabled'}
|
||||
assert props == {'disabled'}
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
api.option('c').value.get()
|
||||
cfg.option('c').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert props == ['disabled']
|
||||
else:
|
||||
assert props == {'disabled'}
|
||||
assert props == {'disabled'}
|
||||
|
||||
|
||||
def test_symlink_multi():
|
||||
def test_symlink_multi(config_type):
|
||||
boolopt = BoolOption("b", "", default=[False], multi=True)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
assert api.option('s1.b').value.get() == [False]
|
||||
assert api.option('c').value.get() == [False]
|
||||
api.option('s1.b').value.set([True])
|
||||
assert api.option('s1.b').value.get() == [True]
|
||||
assert api.option('c').value.get() == [True]
|
||||
api.option('s1.b').value.set([False])
|
||||
assert api.option('s1.b').value.get() == [False]
|
||||
assert api.option('c').value.get() == [False]
|
||||
api.option('s1.b').value.set([False, True])
|
||||
assert api.option('s1.b').value.get() == [False, True]
|
||||
assert api.option('c').value.get() == [False, True]
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('s1.b').value.get() == [False]
|
||||
assert cfg.option('c').value.get() == [False]
|
||||
cfg.option('s1.b').value.set([True])
|
||||
assert cfg.option('s1.b').value.get() == [True]
|
||||
assert cfg.option('c').value.get() == [True]
|
||||
cfg.option('s1.b').value.set([False])
|
||||
assert cfg.option('s1.b').value.get() == [False]
|
||||
assert cfg.option('c').value.get() == [False]
|
||||
cfg.option('s1.b').value.set([False, True])
|
||||
assert cfg.option('s1.b').value.get() == [False, True]
|
||||
assert cfg.option('c').value.get() == [False, True]
|
||||
assert boolopt.impl_is_multi() is True
|
||||
assert linkopt.impl_is_multi() is True
|
||||
|
||||
|
||||
def test_symlink_assign():
|
||||
if TIRAMISU_VERSION != 2:
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
raises(ConfigError, "api.option('c').value.set(True)")
|
||||
|
||||
|
||||
def test_symlink_owner():
|
||||
def test_symlink_assign(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
assert api.option('s1.b').owner.isdefault()
|
||||
assert api.option('c').owner.isdefault()
|
||||
api.option('s1.b').value.set(True)
|
||||
assert not api.option('s1.b').owner.isdefault()
|
||||
assert not api.option('c').owner.isdefault()
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(ConfigError, "cfg.option('c').value.set(True)")
|
||||
|
||||
|
||||
def test_symlink_owner(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('s1.b').owner.isdefault()
|
||||
assert cfg.option('c').owner.isdefault()
|
||||
cfg.option('s1.b').value.set(True)
|
||||
assert not cfg.option('s1.b').owner.isdefault()
|
||||
assert not cfg.option('c').owner.isdefault()
|
||||
|
||||
|
||||
def test_symlink_get_information():
|
||||
@ -224,41 +221,44 @@ def test_symlink_followers():
|
||||
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
||||
|
||||
|
||||
def test_symlink_with_leader():
|
||||
def test_symlink_with_leader(config_type):
|
||||
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)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
leader = SymLinkOption('leader', ip_admin_eth0)
|
||||
od = OptionDescription('root', '', [interface1, leader])
|
||||
api = Config(od)
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']}
|
||||
cfg = Config(od)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []}
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']}
|
||||
|
||||
|
||||
def test_symlink_with_follower():
|
||||
def test_symlink_with_follower(config_type):
|
||||
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)
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
follower = SymLinkOption('follower', netmask_admin_eth0)
|
||||
od = OptionDescription('root', '', [interface1, follower])
|
||||
api = Config(od)
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []}
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]}
|
||||
cfg = Config(od)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []}
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
print(cfg.value.dict())
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]}
|
||||
#
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
|
||||
assert api.option('follower', 0).value.get() == None
|
||||
assert api.option('follower', 1).value.get() == None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
|
||||
assert cfg.option('follower', 0).value.get() == None
|
||||
assert cfg.option('follower', 1).value.get() == None
|
||||
#
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
|
||||
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']}
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']}
|
||||
#
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
|
||||
assert api.option('follower', 0).value.get() == None
|
||||
assert api.option('follower', 1).value.get() == 'val3'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
|
||||
assert cfg.option('follower', 0).value.get() == None
|
||||
assert cfg.option('follower', 1).value.get() == 'val3'
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
@ -267,36 +267,38 @@ def test_symlink_dependency():
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
assert api.option('s1.b').option.has_dependency() is False
|
||||
assert api.option('c').option.has_dependency() is True
|
||||
assert api.option('s1.b').option.has_dependency(False) is True
|
||||
assert api.option('c').option.has_dependency(False) is False
|
||||
cfg = Config(descr)
|
||||
assert cfg.option('s1.b').option.has_dependency() is False
|
||||
assert cfg.option('c').option.has_dependency() is True
|
||||
assert cfg.option('s1.b').option.has_dependency(False) is True
|
||||
assert cfg.option('c').option.has_dependency(False) is False
|
||||
|
||||
|
||||
def test_symlink_makedict():
|
||||
def test_symlink_makedict(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
assert api.value.dict() == {'c': False, 's1.b': False}
|
||||
api.option('s1.b').value.set(True)
|
||||
assert api.value.dict() == {'c': True, 's1.b': True}
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'c': False, 's1.b': False}
|
||||
cfg.option('s1.b').value.set(True)
|
||||
assert cfg.value.dict() == {'c': True, 's1.b': True}
|
||||
|
||||
|
||||
def test_symlink_list():
|
||||
def test_symlink_list(config_type):
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
api = Config(descr)
|
||||
cfg = Config(descr)
|
||||
cfg = get_config(cfg, config_type)
|
||||
list_opt = []
|
||||
for opt in api.option.list():
|
||||
for opt in cfg.option.list():
|
||||
list_opt.append(opt.option.path())
|
||||
assert list_opt == ['c']
|
||||
#
|
||||
list_opt = []
|
||||
for opt in api.option.list(recursive=True):
|
||||
for opt in cfg.option.list(recursive=True):
|
||||
list_opt.append(opt.option.path())
|
||||
assert list_opt == ['c', 's1.b']
|
||||
|
@ -278,6 +278,11 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
|
||||
option = self._option_bag.option
|
||||
return option.impl_get_callback()
|
||||
|
||||
def validator(self):
|
||||
"""Get validator for an option (not for optiondescription)"""
|
||||
option = self._option_bag.option
|
||||
return option.impl_get_validator()
|
||||
|
||||
def pattern(self) -> str:
|
||||
option = self._option_bag.option
|
||||
type = option.get_type()
|
||||
@ -374,7 +379,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
only_raises=False):
|
||||
"""Get properties for an option"""
|
||||
option = self._option_bag.option
|
||||
self._test_follower_index()
|
||||
#self._test_follower_index()
|
||||
if not only_raises:
|
||||
return self._option_bag.properties
|
||||
# do not check cache properties/permissives which are not save (unrestraint, ...)
|
||||
@ -677,7 +682,6 @@ class _TiramisuOption(CommonTiramisu):
|
||||
if subfunc in self._registers:
|
||||
subconfig = self._subconfig
|
||||
if subconfig:
|
||||
option_bag = self._option_bag
|
||||
option = self._get_option()
|
||||
if option.impl_is_optiondescription() and subfunc == 'option':
|
||||
config = self._get_config()
|
||||
|
@ -43,7 +43,7 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
|
||||
if config_bag is undefined:
|
||||
return undefined
|
||||
if isinstance(callbk, ParamContext):
|
||||
#Not an option, set full context
|
||||
# Not an option, set full context
|
||||
return config_bag.context.duplicate(force_values=get_default_values_storages(),
|
||||
force_settings=get_default_settings_storages())
|
||||
opt = callbk.option
|
||||
|
@ -249,7 +249,7 @@ class SubConfig(object):
|
||||
_commit=True):
|
||||
option = option_bag.option
|
||||
if option.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't delete a SymLinkOption"))
|
||||
raise ConfigError(_("can't delete a SymLinkOption"))
|
||||
values = self.cfgimpl_get_values()
|
||||
if option_bag.index is not None:
|
||||
values.reset_follower(option_bag,
|
||||
|
@ -85,8 +85,10 @@ class PropertiesOptionError(AttributeError):
|
||||
|
||||
def __str__(self):
|
||||
#this part is a bit slow, so only execute when display
|
||||
if self.msg:
|
||||
if self.msg is not None:
|
||||
return self.msg
|
||||
if self._settings is None:
|
||||
return 'error'
|
||||
req = self._settings.apply_requires(self._option_bag,
|
||||
True)
|
||||
#if req != {} or self._orig_opt is not None:
|
||||
|
@ -183,6 +183,7 @@ class ConfigBag:
|
||||
__slots__ = ('context', # link to the current context
|
||||
'properties', # properties for current context
|
||||
'true_properties', # properties for current context
|
||||
'is_unrestraint',
|
||||
'permissives', # permissives for current context
|
||||
'expiration_time' # EXPIRATION_TIME
|
||||
)
|
||||
@ -206,6 +207,8 @@ class ConfigBag:
|
||||
if key == 'expiration_time':
|
||||
self.expiration_time = EXPIRATION_TIME
|
||||
return self.expiration_time
|
||||
if key == 'is_unrestraint':
|
||||
return False
|
||||
raise KeyError('unknown key {} for ConfigBag'.format(key)) # pragma: no cover
|
||||
|
||||
def remove_warnings(self):
|
||||
@ -215,6 +218,7 @@ class ConfigBag:
|
||||
self.properties = frozenset(self.properties - {'validator'})
|
||||
|
||||
def unrestraint(self):
|
||||
self.is_unrestraint = True
|
||||
self.true_properties = self.properties
|
||||
self.properties = frozenset(['cache'])
|
||||
|
||||
@ -437,7 +441,8 @@ class Settings(object):
|
||||
search_properties=search_properties)
|
||||
props -= self.getpermissives(opt,
|
||||
path)
|
||||
if apply_requires:
|
||||
#if apply_requires and config_bag.properties == config_bag.true_properties:
|
||||
if apply_requires and not config_bag.is_unrestraint:
|
||||
self._p_.setcache(path,
|
||||
index,
|
||||
props,
|
||||
@ -761,15 +766,23 @@ class Settings(object):
|
||||
def calc_raises_properties(self,
|
||||
option_bag,
|
||||
apply_requires=True):
|
||||
raises_properties = option_bag.config_bag.properties - SPECIAL_PROPERTIES
|
||||
# remove global permissive properties
|
||||
if raises_properties and ('permissive' in raises_properties):
|
||||
raises_properties -= option_bag.config_bag.permissives
|
||||
if apply_requires and option_bag.properties_setted:
|
||||
option_properties = option_bag.properties
|
||||
else:
|
||||
option_properties = self.getproperties(option_bag,
|
||||
apply_requires=apply_requires)
|
||||
return self._calc_raises_properties(option_bag.config_bag.properties,
|
||||
option_bag.config_bag.permissives,
|
||||
option_properties)
|
||||
|
||||
def _calc_raises_properties(self,
|
||||
context_properties,
|
||||
context_permissives,
|
||||
option_properties):
|
||||
raises_properties = context_properties - SPECIAL_PROPERTIES
|
||||
# remove global permissive properties
|
||||
if raises_properties and ('permissive' in raises_properties):
|
||||
raises_properties -= context_permissives
|
||||
properties = option_properties & raises_properties
|
||||
# at this point an option should not remain in properties
|
||||
return properties
|
||||
|
@ -30,8 +30,6 @@ INPUTS = ['string',
|
||||
'ip',
|
||||
'domainname']
|
||||
|
||||
ACTION_HIDE = ['hidden', 'disabled']
|
||||
|
||||
|
||||
# return always warning (even if same warning is already returned)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
@ -137,62 +135,89 @@ class Requires(object):
|
||||
self.requires = {}
|
||||
self.options = {}
|
||||
self.tiramisu_web = tiramisu_web
|
||||
self.action_hide = self.tiramisu_web.config._config_bag.properties
|
||||
|
||||
def manage_requires(self,
|
||||
childapi,
|
||||
path,
|
||||
form,
|
||||
action_hide,
|
||||
current_action):
|
||||
for requires in childapi.option.requires():
|
||||
len_to_long = len(requires) > 1
|
||||
if childapi.option.isoptiondescription():
|
||||
isfollower = False
|
||||
else:
|
||||
isfollower = childapi.option.isfollower()
|
||||
if isfollower:
|
||||
parent_path = path.rsplit('.', 1)[0]
|
||||
parent = self.tiramisu_web.config.unrestraint.option(parent_path)
|
||||
leader = next(parent.list())
|
||||
self.tiramisu_web.set_remotable(leader.option.path(), form, leader)
|
||||
for require in requires:
|
||||
options, action, inverse, \
|
||||
transitive, same_action, operator = require
|
||||
if transitive is False or same_action is False or operator == 'and':
|
||||
# transitive to "False" not supported yet for a requirement
|
||||
# same_action to "False" not supported yet for a requirement
|
||||
# operator "and" not supported yet for a requirement
|
||||
self.tiramisu_web.set_remotable(path, form, childapi)
|
||||
return
|
||||
options, action, inverse, transitive, same_action, operator = require
|
||||
if not len_to_long:
|
||||
len_to_long = len(options) > 1
|
||||
for option, expected in options:
|
||||
option_path = option.impl_getpath()
|
||||
if action in action_hide:
|
||||
if isinstance(option, ChoiceOption):
|
||||
choice_obj = self.tiramisu_web.config.unrestraint.option(option_path)
|
||||
if choice_obj.value.is_values_callback():
|
||||
self.tiramisu_web.set_remotable(option_path, form, choice_obj)
|
||||
return
|
||||
else:
|
||||
values = self.tiramisu_web.get_enum(choice_obj,
|
||||
choice_obj.option.ismulti(),
|
||||
option_path,
|
||||
choice_obj.option.properties())
|
||||
for value in values:
|
||||
if value not in expected:
|
||||
self.requires.setdefault(path,
|
||||
{'expected': {}}
|
||||
)['expected'].setdefault(value,
|
||||
{}).setdefault(inv_act,
|
||||
[]).append(option_path)
|
||||
if current_action is None:
|
||||
current_action = action
|
||||
elif current_action != action:
|
||||
self.tiramisu_web.set_remotable(option_path, form)
|
||||
if inverse:
|
||||
act = 'show'
|
||||
inv_act = 'hide'
|
||||
else:
|
||||
act = 'hide'
|
||||
inv_act = 'show'
|
||||
for exp in expected:
|
||||
self.requires.setdefault(path,
|
||||
{'expected': {}}
|
||||
)['expected'].setdefault(exp,
|
||||
{}).setdefault(act,
|
||||
[]).append(option_path)
|
||||
self.requires[path].setdefault('default', {}).setdefault(inv_act, []).append(option_path)
|
||||
if isinstance(option, tuple):
|
||||
for option_param in chain(option[1].args, option[1].kwargs.values()):
|
||||
if isinstance(option_param, ParamOption):
|
||||
self.tiramisu_web.set_remotable(option_param.option.impl_getpath(), form)
|
||||
elif len_to_long:
|
||||
self.tiramisu_web.set_remotable(option.impl_getpath(), form)
|
||||
else:
|
||||
self.tiramisu_web.set_remotable(option_path, form)
|
||||
option_path = option.impl_getpath()
|
||||
if action in self.action_hide:
|
||||
if childapi.option.isoptiondescription() or isfollower:
|
||||
self.tiramisu_web.set_remotable(option_path, form)
|
||||
continue
|
||||
require_option = self.tiramisu_web.config.unrestraint.option(option_path)
|
||||
if transitive is False or same_action is False or operator == 'and':
|
||||
# transitive to "False" not supported yet for a requirement
|
||||
# same_action to "False" not supported yet for a requirement
|
||||
# operator "and" not supported yet for a requirement
|
||||
self.tiramisu_web.set_remotable(option_path, form, require_option)
|
||||
if require_option.option.requires():
|
||||
for reqs in require_option.option.requires():
|
||||
for req in reqs:
|
||||
for subopt, subexp in req[0]:
|
||||
if not isinstance(subopt, tuple):
|
||||
self.tiramisu_web.set_remotable(subopt.impl_getpath(), form)
|
||||
if isinstance(option, ChoiceOption):
|
||||
require_option = self.tiramisu_web.config.unrestraint.option(option_path)
|
||||
if require_option.value.callbacks():
|
||||
self.tiramisu_web.set_remotable(option_path, form, require_option)
|
||||
continue
|
||||
else:
|
||||
values = self.tiramisu_web.get_enum(require_option,
|
||||
require_option.option.ismulti(),
|
||||
option_path,
|
||||
require_option.option.properties())
|
||||
for value in values:
|
||||
if value not in expected:
|
||||
self.requires.setdefault(path,
|
||||
{'expected': {}}
|
||||
)['expected'].setdefault(value,
|
||||
{}).setdefault(inv_act,
|
||||
[]).append(option_path)
|
||||
if current_action is None:
|
||||
current_action = action
|
||||
elif current_action != action:
|
||||
self.tiramisu_web.set_remotable(option_path, form)
|
||||
if inverse:
|
||||
act = 'show'
|
||||
inv_act = 'hide'
|
||||
else:
|
||||
act = 'hide'
|
||||
inv_act = 'show'
|
||||
for exp in expected:
|
||||
self.requires.setdefault(path,
|
||||
{'expected': {}}
|
||||
)['expected'].setdefault(exp,
|
||||
{}).setdefault(act,
|
||||
[]).append(option_path)
|
||||
self.requires[path].setdefault('default', {}).setdefault(inv_act, []).append(option_path)
|
||||
else:
|
||||
self.tiramisu_web.set_remotable(option_path, form)
|
||||
|
||||
def add(self, path, childapi, form):
|
||||
#collect id of all options
|
||||
@ -205,7 +230,6 @@ class Requires(object):
|
||||
self.manage_requires(childapi,
|
||||
path,
|
||||
form,
|
||||
ACTION_HIDE,
|
||||
current_action)
|
||||
|
||||
def is_remote(self, path, form):
|
||||
@ -217,8 +241,6 @@ class Requires(object):
|
||||
def process(self, form):
|
||||
dependencies = {}
|
||||
for path, values in self.requires.items():
|
||||
if form.get(path, {}).get('remote') is True:
|
||||
continue
|
||||
if 'default' in values:
|
||||
for option in values['default'].get('show', []):
|
||||
if path == option:
|
||||
@ -262,7 +284,7 @@ class Requires(object):
|
||||
if path not in dependencies[option]['expected'][expected]['hide']:
|
||||
dependencies[option]['expected'][expected]['hide'].append(path)
|
||||
for path, dependency in dependencies.items():
|
||||
form[path]['dependencies'] = dependency
|
||||
form.setdefault(path, {})['dependencies'] = dependency
|
||||
|
||||
|
||||
class TiramisuDict:
|
||||
@ -375,7 +397,6 @@ class TiramisuDict:
|
||||
childapi,
|
||||
path,
|
||||
leader_len,
|
||||
props_no_requires,
|
||||
updates_status)
|
||||
if order is not None:
|
||||
order.append(path)
|
||||
@ -405,6 +426,9 @@ class TiramisuDict:
|
||||
childtype = child._impl_getopt().__class__.__name__
|
||||
if childapi_option.issymlinkoption():
|
||||
web_type = 'symlink'
|
||||
value = None
|
||||
defaultmulti = None
|
||||
is_multi = False
|
||||
else:
|
||||
web_type = childapi_option.type()
|
||||
value = childapi.option.default()
|
||||
@ -443,6 +467,8 @@ class TiramisuDict:
|
||||
self.add_help(schema[path],
|
||||
childapi)
|
||||
except Exception as err:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
if not init:
|
||||
raise err
|
||||
error = err
|
||||
@ -524,6 +550,15 @@ class TiramisuDict:
|
||||
if path in form:
|
||||
obj_form.update(form[path])
|
||||
if not childapi_option.issymlinkoption():
|
||||
if childapi_option.validator() != (None, None):
|
||||
obj_form['remote'] = True
|
||||
params = childapi_option.validator()[1]
|
||||
if params is not None:
|
||||
for param in chain(params.args, params.kwargs.values()):
|
||||
if isinstance(param, ParamContext):
|
||||
raise ValueError(_('context is not supported from now for {}').format(path))
|
||||
if isinstance(param, ParamOption):
|
||||
self.set_remotable(param.option.impl_getpath(), form)
|
||||
if self.clearable == 'all':
|
||||
obj_form['clearable'] = True
|
||||
if self.clearable != 'none':
|
||||
@ -532,6 +567,8 @@ class TiramisuDict:
|
||||
obj_form['remote'] = True
|
||||
if childtype == 'IPOption' and (child.impl_get_extra('_private_only') or not child.impl_get_extra('_allow_reserved') or child.impl_get_extra('_cidr')):
|
||||
obj_form['remote'] = True
|
||||
if childtype == 'DateOption':
|
||||
obj_form['remote'] = True
|
||||
if not obj_form.get('remote', False):
|
||||
pattern = childapi_option.pattern()
|
||||
if pattern is not None:
|
||||
@ -553,28 +590,32 @@ class TiramisuDict:
|
||||
childapi):
|
||||
old_properties = childapi._option_bag.config_bag.properties
|
||||
del childapi._option_bag.config_bag.properties
|
||||
if 'permissive' not in childapi._option_bag.config_bag.properties:
|
||||
has_permissive = 'permissive' in childapi._option_bag.config_bag.properties
|
||||
if not has_permissive:
|
||||
childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties | {'permissive'}
|
||||
# 'display=False' means cannot access only without permissive option
|
||||
# 'hidden=True' means cannot access with or without permissive option
|
||||
if childapi.option.properties(only_raises=True):
|
||||
properties = childapi.property.get(only_raises=True)
|
||||
if has_permissive:
|
||||
properties -= self.config.permissive.get()
|
||||
properties -= childapi.permissive.get()
|
||||
if properties:
|
||||
obj['hidden'] = True
|
||||
childapi._option_bag.config_bag.properties = childapi._option_bag.config_bag.properties - {'permissive'}
|
||||
if childapi.option.properties(only_raises=True):
|
||||
properties = childapi.property.get(only_raises=True)
|
||||
if has_permissive:
|
||||
properties -= self.config.permissive.get()
|
||||
properties -= childapi.permissive.get()
|
||||
if properties:
|
||||
obj['display'] = False
|
||||
childapi._option_bag.config_bag.properties = old_properties
|
||||
|
||||
def _gen_model_properties(self,
|
||||
childapi,
|
||||
path,
|
||||
index,
|
||||
props_no_requires):
|
||||
index):
|
||||
isfollower = childapi.option.isfollower()
|
||||
if index is None and isfollower:
|
||||
# cannot calculated requires with follower without index
|
||||
props = props_no_requires
|
||||
else:
|
||||
props = set(childapi.property.get())
|
||||
props = set(childapi.property.get())
|
||||
obj = self.gen_properties(props,
|
||||
isfollower,
|
||||
childapi.option.ismulti())
|
||||
@ -589,22 +630,16 @@ class TiramisuDict:
|
||||
if not isfollower and ismulti:
|
||||
if 'empty' in properties:
|
||||
obj['required'] = True
|
||||
properties.remove('empty')
|
||||
if 'mandatory' in properties:
|
||||
obj['needs_len'] = True
|
||||
properties.remove('mandatory')
|
||||
elif 'mandatory' in properties:
|
||||
obj['required'] = True
|
||||
properties.remove('mandatory')
|
||||
if 'frozen' in properties:
|
||||
obj['readOnly'] = True
|
||||
properties.remove('frozen')
|
||||
#if 'hidden' in properties:
|
||||
# obj['hidden'] = True
|
||||
# properties.remove('hidden')
|
||||
#if 'disabled' in properties:
|
||||
# obj['hidden'] = True
|
||||
# properties.remove('disabled')
|
||||
if properties:
|
||||
lprops = list(properties)
|
||||
lprops.sort()
|
||||
@ -616,7 +651,6 @@ class TiramisuDict:
|
||||
childapi,
|
||||
path,
|
||||
leader_len,
|
||||
props_no_requires,
|
||||
updates_status):
|
||||
if childapi.option.isoptiondescription():
|
||||
props = set(childapi.property.get())
|
||||
@ -633,15 +667,13 @@ class TiramisuDict:
|
||||
else:
|
||||
obj = self._gen_model_properties(childapi,
|
||||
path,
|
||||
None,
|
||||
props_no_requires)
|
||||
None)
|
||||
if childapi.option.isfollower():
|
||||
for index in range(leader_len):
|
||||
follower_childapi = self.config.unrestraint.option(path, index)
|
||||
sobj = self._gen_model_properties(follower_childapi,
|
||||
path,
|
||||
index,
|
||||
props_no_requires)
|
||||
index)
|
||||
self._get_model_value(follower_childapi,
|
||||
path,
|
||||
sobj,
|
||||
@ -657,7 +689,7 @@ class TiramisuDict:
|
||||
updates_status)
|
||||
if obj:
|
||||
if not childapi.option.isoptiondescription() and childapi.option.isfollower():
|
||||
model.setdefault(path, {})[None] = obj
|
||||
model.setdefault(path, {})['null'] = obj
|
||||
else:
|
||||
model[path] = obj
|
||||
|
||||
@ -675,9 +707,8 @@ class TiramisuDict:
|
||||
del updates_status[path][index]
|
||||
else:
|
||||
try:
|
||||
nchildapi = self.config.option(path, index=index)
|
||||
with warnings.catch_warnings(record=True) as warns:
|
||||
value = nchildapi.value.get()
|
||||
value = self.config.option(path, index=index).value.get()
|
||||
self._get_value_with_exception(obj,
|
||||
childapi,
|
||||
warns)
|
||||
@ -687,6 +718,13 @@ class TiramisuDict:
|
||||
[err])
|
||||
value = self.config.unrestraint.option(path, index=index).value.get()
|
||||
except PropertiesOptionError as err:
|
||||
config_bag = self.config._config_bag
|
||||
settings = config_bag.context.cfgimpl_get_settings()
|
||||
if settings._calc_raises_properties(config_bag.properties,
|
||||
config_bag.permissives,
|
||||
set(err.proptype)):
|
||||
obj['hidden'] = True
|
||||
obj['display'] = False
|
||||
value = childapi.value.get()
|
||||
if value is not None and value != []:
|
||||
obj['value'] = value
|
||||
@ -852,7 +890,6 @@ class TiramisuDict:
|
||||
buttons = []
|
||||
else:
|
||||
form = None
|
||||
ret = {}
|
||||
self.walk(rootpath,
|
||||
None,
|
||||
schema,
|
||||
|
Loading…
Reference in New Issue
Block a user