better hidden/display support
This commit is contained in:
@ -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']
|
||||
|
Reference in New Issue
Block a user