tiramisu/tests/test_mandatory.py

737 lines
28 KiB
Python
Raw Permalink Normal View History

# coding: utf-8
2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
2019-06-21 23:04:04 +02:00
# FIXME from .config import config_type, get_config
2019-12-24 15:24:20 +01:00
import pytest
2018-08-14 22:15:40 +02:00
from tiramisu import Config
from tiramisu import IntOption, StrOption, OptionDescription, DynOptionDescription, PasswordOption, UsernameOption, \
SymLinkOption, Leadership, Calculation, Params, \
2023-04-27 11:34:35 +02:00
ParamOption, ParamValue, ParamIndex, calc_value
2015-10-29 09:03:13 +01:00
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups
2018-10-31 08:00:19 +01:00
2020-01-22 20:46:18 +01:00
#def teardown_function(function):
# assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def is_mandatory(variable):
return True
def make_description():
stro = StrOption('str', '')
subdescr = OptionDescription('sub', '', [stro], properties=('disabled',))
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
2019-12-08 09:09:48 +01:00
stroption2 = StrOption('unicode2', 'Test string option',
properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
2019-12-08 09:09:48 +01:00
descr = OptionDescription('tiram', '', [subdescr, stroption, stroption1, stroption2, stroption3])
return descr
2015-10-29 09:03:13 +01:00
def return_value(value):
return value
def make_description2():
2023-04-27 11:34:35 +02:00
stroption = StrOption('str', 'str', default="abc",
2015-10-29 09:03:13 +01:00
properties=('mandatory', ))
2023-04-27 11:34:35 +02:00
stroption1 = StrOption('str1', 'str1',
2015-10-29 09:03:13 +01:00
properties=('mandatory', ))
stroption2 = SymLinkOption('unicode2', stroption1)
2023-04-27 11:34:35 +02:00
stroption3 = StrOption('str3', 'str3', multi=True,
2015-10-29 09:03:13 +01:00
properties=('mandatory', ))
2023-04-27 11:34:35 +02:00
unicode1 = StrOption('unicode1', 'unicode1', Calculation(return_value, Params(ParamOption(stroption))), properties=('mandatory',))
2015-10-29 09:03:13 +01:00
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
return descr
def make_description_sym():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
return descr
def make_description3():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
2019-12-08 09:09:48 +01:00
unicode1 = StrOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
int1 = IntOption('int1', '', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
2015-10-29 09:03:13 +01:00
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
return descr
def test_mandatory_ro():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_only()
prop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.property.read_only()
assert cfg.option('str1').value.get() == 'yes'
# assert not list_sessions()
def test_mandatory_ro_dict():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_only()
prop = []
try:
cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.option('unicode2').value.set('yes')
cfg.property.read_only()
try:
cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str3').value.set(['yes'])
cfg.property.read_only()
assert cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'unicode2': 'yes'}
# assert not list_sessions()
def test_mandatory_rw():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
# not mandatory in rw
cfg.option('str1').value.get()
cfg.option('str1').value.set('yes')
assert cfg.option('str1').value.get() == 'yes'
# assert not list_sessions()
def test_mandatory_default():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_only()
#not mandatory in rw
cfg.option('str').value.get()
cfg.property.read_write()
cfg.option('str').value.set('yes')
cfg.property.read_only()
cfg.option('str').value.get()
cfg.property.read_write()
cfg.option('str').value.set(None)
cfg.property.read_only()
prop = []
try:
cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
# assert not list_sessions()
def test_mandatory_delete():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_only()
cfg.option('str').value.get()
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.property.read_only()
assert cfg.option('str1').value.get() == 'yes'
cfg.property.remove('everything_frozen')
prop = []
try:
cfg.option('str1').value.reset()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.option('str').value.reset()
assert cfg.option('str1').value.get() == 'yes'
# assert not list_sessions()
2015-12-17 22:41:57 +01:00
#valeur vide : None, '', u'', ...
def test_mandatory_none():
od1 = make_description()
cfg = Config(od1)
cfg.option('str1').value.set(None)
assert cfg.option('str1').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
# assert not list_sessions()
def test_mandatory_empty():
od1 = make_description()
cfg = Config(od1)
cfg.option('str1').value.set('')
assert cfg.option('str1').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
# assert not list_sessions()
def test_mandatory_multi_none():
od1 = make_description()
cfg = Config(od1)
cfg.option('str3').value.set([None])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str3').value.set(['yes', None])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
# assert not list_sessions()
def test_mandatory_multi_empty():
od1 = make_description()
cfg = Config(od1)
cfg.option('str3').value.set([])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
cfg.property.read_write()
cfg.option('str3').value.set([''])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
cfg.property.read_write()
cfg.option('str3').value.set(['yes', ''])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
# assert not list_sessions()
def test_mandatory_multi_append():
od1 = make_description()
cfg = Config(od1)
cfg.option('str3').value.set(['yes'])
cfg.property.read_write()
ret = cfg.option('str3').value.get()
ret.append(None)
# assert not list_sessions()
def test_mandatory_disabled():
od1 = make_description()
cfg = Config(od1)
cfg.option('str1').value.get()
cfg.option('str1').property.add('disabled')
cfg.property.read_only()
pop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
search_prop = {'disabled'}
assert set(prop) == search_prop
# assert not list_sessions()
def test_mandatory_unicode():
od1 = make_description()
cfg = Config(od1)
cfg.option('unicode2').value.get()
cfg.property.read_only()
prop = []
try:
cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('unicode2').value.set(u'')
cfg.property.read_only()
prop = []
try:
cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
# assert not list_sessions()
2023-04-27 11:34:35 +02:00
def compare(ret, expected):
assert(len(ret) == len(expected))
for index, opt in enumerate(ret):
exp = expected[index]
if isinstance(exp, list):
assert opt.path() == exp[0]
assert opt.index() == exp[1]
2023-04-27 11:34:35 +02:00
else:
assert opt.path() == exp
assert opt.index() == None
2023-04-27 11:34:35 +02:00
def test_mandatory_warnings_ro():
od1 = make_description()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_only()
proc = []
try:
cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
cfg.property.read_write()
cfg.option('str').value.set('a')
cfg.property.read_only()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
# assert not list_sessions()
def test_mandatory_warnings_rw():
od1 = make_description()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
cfg.option('str').value.set('a')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
# assert not list_sessions()
def test_mandatory_warnings_disabled():
od1 = make_description()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
cfg.option('str').property.add('disabled')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
# assert not list_sessions()
def test_mandatory_warnings_hidden():
od1 = make_description()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.permissive.add('hidden')
cfg.option('str').value.get()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
cfg.option('str').property.add('hidden')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
# assert not list_sessions()
def test_mandatory_warnings_frozen():
od1 = make_description()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
cfg.option('str').property.add('frozen')
cfg.property.read_only()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
# assert not list_sessions()
def test_mandatory_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
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])
od1 = OptionDescription('o', '', [interface1])
cfg = Config(od1)
cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
cfg.value.dict()
# assert not list_sessions()
def test_mandatory_leader_sub():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('o', '', [interface1])
od2 = OptionDescription('o', '', [od1])
cfg = Config(od2)
cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
cfg.option('o.ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
cfg.value.dict()
# assert not list_sessions()
def test_mandatory_warnings_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('o', '', [interface1])
cfg = Config(od1)
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['ip_admin_eth0.ip_admin_eth0'])
# assert not list_sessions()
def test_mandatory_leader_empty():
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)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('o', '', [interface1])
cfg = Config(od1)
cfg.property.read_write()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cfg.property.read_write()
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
# assert not list_sessions()
def test_mandatory_warnings_leader_empty():
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)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('o', '', [interface1])
cfg = Config(od1)
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['ip_admin_eth0.ip_admin_eth0'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['ip_admin_eth0.ip_admin_eth0'])
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [])
# assert not list_sessions()
def test_mandatory_follower():
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, properties=('mandatory', ))
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('o', '', [interface1])
cfg = Config(od1)
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
2023-04-27 11:34:35 +02:00
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': []}
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
with pytest.raises(PropertiesOptionError):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
2023-04-27 11:34:35 +02:00
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip', 'ip_admin_eth0.netmask_admin_eth0': 'ip'}]}
# assert not list_sessions()
def test_mandatory_warnings_follower():
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, properties=('mandatory', ))
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('o', '', [interface1])
cfg = Config(od1)
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.property.read_write()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [['ip_admin_eth0.netmask_admin_eth0', 0]])
# assert not list_sessions()
def test_mandatory_warnings_symlink():
od1 = make_description_sym()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'str3'])
cfg.option('str').property.add('frozen')
cfg.property.read_only()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'str3'])
# assert not list_sessions()
def test_mandatory_warnings_validate_empty():
od1 = make_description2()
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_only()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'str3', 'unicode1'])
# assert not list_sessions()
def test_mandatory_warnings_requires():
2018-04-06 16:09:10 +02:00
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
2019-12-08 09:09:48 +01:00
stroption2 = StrOption('unicode2', 'Test string option',
2018-04-06 16:09:10 +02:00
properties=('mandatory', ))
2019-09-01 09:41:53 +02:00
mandatory_property = Calculation(calc_value,
Params(ParamValue('mandatory'),
kwargs={'condition': ParamOption(stroption, notraisepropertyerror=True),
'expected': ParamValue('yes'),
'no_condition_is_invalid': ParamValue(True)}))
stroption3 = StrOption('str3', 'Test string option', multi=True, properties=(mandatory_property,))
od1 = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2'])
cfg.property.read_only()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2'])
cfg.property.read_write()
cfg.option('str').value.set('yes')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
# assert not list_sessions()
def test_mandatory_warnings_requires_leadership():
2018-04-06 16:09:10 +02:00
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option', multi=True)
2019-09-01 09:41:53 +02:00
mandatory_property = Calculation(calc_value,
Params(ParamValue(None),
kwargs={'condition': ParamOption(stroption),
'expected': ParamValue('yes'),
2019-12-08 09:09:48 +01:00
'reverse_condition': ParamValue(True),
2019-09-01 09:41:53 +02:00
'default': ParamValue('mandatory')}))
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
2019-02-23 19:06:23 +01:00
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
od1 = OptionDescription('tiram', '', [stroption, leadership])
cfg = Config(od1)
cfg.option('str').value.set('')
cfg.option('leader.str1').value.set(['str'])
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['str'])
cfg.option('str').value.set('yes')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [['leader.str2', 0]])
# assert not list_sessions()
def test_mandatory_warnings_requires_leadership_follower():
2018-04-06 16:09:10 +02:00
stroption = StrOption('str', 'Test string option', multi=True)
stroption1 = StrOption('str1', 'Test string option', multi=True)
2019-09-01 09:41:53 +02:00
mandatory_property = Calculation(calc_value,
Params(ParamValue(None),
kwargs={'condition': ParamOption(stroption1),
'expected': ParamValue('yes'),
2019-12-08 09:09:48 +01:00
'reverse_condition': ParamValue(True),
2019-09-01 09:41:53 +02:00
'default': ParamValue('mandatory')}))
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
2019-02-23 19:06:23 +01:00
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
od1 = OptionDescription('tiram', '', [leadership])
cfg = Config(od1)
cfg.option('leader.str').value.set(['str'])
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [])
cfg.option('leader.str1', 0).value.set('yes')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [['leader.str2', 0]])
cfg.option('leader.str2', 0).value.set('yes')
compare(cfg.value.mandatory(), [])
#
cfg.option('leader.str').value.set(['str', 'str1'])
compare(cfg.value.mandatory(), [])
cfg.option('leader.str1', 1).value.set('yes')
compare(cfg.value.mandatory(), [['leader.str2', 1]])
cfg.option('leader.str2', 1).value.set('yes')
compare(cfg.value.mandatory(), [])
cfg.option('leader.str2', 0).value.reset()
cfg.option('leader.str2', 1).value.reset()
compare(cfg.value.mandatory(), [['leader.str2', 0], ['leader.str2', 1]])
# assert not list_sessions()
2018-04-06 16:09:10 +02:00
def test_mandatory_od_disabled():
2015-10-29 09:03:13 +01:00
descr = make_description()
od1 = OptionDescription('od', '', [descr])
cfg = Config(od1)
cfg.property.read_only()
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), ['tiram.str1', 'tiram.unicode2', 'tiram.str3'])
cfg.option('tiram').property.add('disabled')
2023-04-27 11:34:35 +02:00
compare(cfg.value.mandatory(), [])
# assert not list_sessions()
def return_list(val=None, suffix=None):
if val:
return val
else:
return ['val1', 'val2']
def test_mandatory_dyndescription():
st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg.property.read_only()
compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st'])
2023-04-27 11:34:35 +02:00
def test_mandatory_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg.property.read_only()
compare(cfg.value.mandatory(), ['od.dodval1.st', 'od.dodval2.st'])
2023-04-27 11:34:35 +02:00
def test_mandatory_callback_leader_and_followers_leader():
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
od1 = OptionDescription('rootconfig', '', [interface1])
cfg = Config(od1)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
compare(cfg.value.mandatory(), ['val1.val1'])
# assert not list_sessions()
def test_mandatory_and_disabled():
password = PasswordOption(name="password", doc="Password", properties=frozenset({"disabled"}))
username = UsernameOption(name="username", doc="Username", properties=frozenset({"normal", Calculation(is_mandatory, Params((ParamOption(password)))), "disabled"}))
od1 = OptionDescription('rootconfig', '', [username, password])
cfg = Config(od1)
cfg.property.read_write()
cfg.value.dict()