add Calculation to properties
This commit is contained in:
@ -5,12 +5,11 @@ from py.test import raises
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, Leadership
|
||||
from tiramisu import Config
|
||||
from tiramisu import BoolOption, IPOption, IntOption, StrOption, OptionDescription, Leadership, Config, \
|
||||
undefined, Calculation, Params, ParamValue, ParamOption, \
|
||||
list_sessions, default_storage, delete_session, calc_value
|
||||
from tiramisu.error import ConfigError, PropertiesOptionError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu import undefined, Params, ParamValue, ParamOption, \
|
||||
list_sessions, default_storage, delete_session
|
||||
|
||||
|
||||
def teardown_function(function):
|
||||
@ -497,8 +496,12 @@ def test_cache_leader_callback():
|
||||
|
||||
def test_cache_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
@ -545,8 +548,12 @@ def test_cache_requires():
|
||||
|
||||
def test_cache_global_properties():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
|
@ -131,7 +131,7 @@ def test_base_config_in_a_tree():
|
||||
|
||||
|
||||
def test_not_valid_properties():
|
||||
raises(TypeError, "stroption = StrOption('str', 'Test string option', default='abc', properties=['mandatory',])")
|
||||
raises(AssertionError, "stroption = StrOption('str', 'Test string option', default='abc', properties='mandatory')")
|
||||
|
||||
|
||||
def test_information_config():
|
||||
|
@ -9,7 +9,7 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
|
||||
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
|
||||
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
|
||||
OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \
|
||||
Config, Params, ParamOption, ParamValue
|
||||
Config, Params, ParamOption, ParamValue, Calculation, calc_value
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
|
||||
from tiramisu.storage import list_sessions
|
||||
|
||||
@ -494,16 +494,24 @@ def test_decrease_dyndescription_context():
|
||||
|
||||
def test_dyndescription_root():
|
||||
boolean = BoolOption('boolean', '', True)
|
||||
st1 = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolean),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
st1 = StrOption('st', '', properties=(disabled_property,))
|
||||
dod = DynOptionDescription('dod', '', [boolean, st1], callback=return_list)
|
||||
raises(ConfigError, "Config(dod)")
|
||||
|
||||
|
||||
def test_requires_dyndescription():
|
||||
boolean = BoolOption('boolean', '', True)
|
||||
st1 = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
st1 = StrOption('st', '', properties=(disabled_property,))
|
||||
dod = DynOptionDescription('dod', '', [st1], callback=return_list)
|
||||
od1 = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od1, boolean])
|
||||
@ -547,11 +555,18 @@ def test_requires_dyndescription():
|
||||
|
||||
def test_requires_dyndescription_boolean():
|
||||
boolean1 = BoolOption('boolean1', '', True)
|
||||
boolean = BoolOption('boolean', '', True, requires=[{'option': boolean1,
|
||||
'expected': False,
|
||||
'action': 'disabled'}])
|
||||
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolean1, raisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
boolean = BoolOption('boolean', '', True, properties=(disabled_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
st = StrOption('st', '', properties=(disabled_property,))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od, boolean1, boolean])
|
||||
@ -578,8 +593,12 @@ def test_requires_dyndescription_boolean():
|
||||
|
||||
def test_requires_dyndescription_in_dyn():
|
||||
boolean = BoolOption('boolean', '', True)
|
||||
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
st = StrOption('st', '', properties=(disabled_property,))
|
||||
dod = DynOptionDescription('dod', '', [boolean, st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
@ -608,9 +627,12 @@ def test_requires_dyndescription_in_dyn():
|
||||
def test_requires_dyndescription2():
|
||||
boolean = BoolOption('boolean', '', True)
|
||||
st1 = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st1], callback=return_list,
|
||||
requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'default': ParamValue(None)}))
|
||||
dod = DynOptionDescription('dod', '', [st1], callback=return_list, properties=(disabled_property,))
|
||||
od1 = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od1, boolean])
|
||||
api = Config(od2)
|
||||
|
@ -8,7 +8,7 @@ from py.test import raises
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, Leadership, Config, \
|
||||
Params, ParamContext, ParamOption, ParamValue
|
||||
Calculation, Params, ParamContext, ParamOption, ParamValue, calc_value
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.storage import list_sessions
|
||||
|
||||
@ -41,14 +41,23 @@ def make_description_freeze():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(booloption, raisepropertyerror=True),
|
||||
'expected': ParamValue(True),
|
||||
'default': ParamValue(None)}))
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value', hidden_property))
|
||||
wantref2_option = BoolOption('wantref2', 'Test requires', default=False, properties=('force_store_value', 'hidden'))
|
||||
wantref3_option = BoolOption('wantref3', 'Test requires', default=[False], multi=True, properties=('force_store_value',))
|
||||
st2 = SymLinkOption('st2', wantref3_option)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(booloption, raisepropertyerror=True),
|
||||
'expected': ParamValue(True),
|
||||
'default': ParamValue(None)}))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
||||
properties=(hidden_property,))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
|
@ -6,7 +6,8 @@ do_autopath()
|
||||
from py.test import raises
|
||||
from tiramisu import Config
|
||||
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
|
||||
SymLinkOption, Leadership, undefined, Params, ParamOption
|
||||
SymLinkOption, Leadership, undefined, Calculation, Params, \
|
||||
ParamOption, ParamValue, calc_value
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.storage import list_sessions
|
||||
@ -575,7 +576,12 @@ def test_mandatory_warnings_requires():
|
||||
properties=('mandatory', ))
|
||||
stroption2 = UnicodeOption('unicode2', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
|
||||
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,))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
||||
cfg = Config(descr)
|
||||
cfg.option('str').value.set('')
|
||||
@ -593,7 +599,13 @@ def test_mandatory_warnings_requires_leadership():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option', multi=True)
|
||||
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
|
||||
mandatory_property = Calculation(calc_value,
|
||||
Params(ParamValue(None),
|
||||
kwargs={'condition': ParamOption(stroption),
|
||||
'expected': ParamValue('yes'),
|
||||
'inverse_condition': ParamValue(True),
|
||||
'default': ParamValue('mandatory')}))
|
||||
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
|
||||
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
|
||||
descr = OptionDescription('tiram', '', [stroption, leadership])
|
||||
cfg = Config(descr)
|
||||
@ -607,7 +619,13 @@ def test_mandatory_warnings_requires_leadership():
|
||||
def test_mandatory_warnings_requires_leadership_follower():
|
||||
stroption = StrOption('str', 'Test string option', multi=True)
|
||||
stroption1 = StrOption('str1', 'Test string option', multi=True)
|
||||
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
|
||||
mandatory_property = Calculation(calc_value,
|
||||
Params(ParamValue(None),
|
||||
kwargs={'condition': ParamOption(stroption1),
|
||||
'expected': ParamValue('yes'),
|
||||
'inverse_condition': ParamValue(True),
|
||||
'default': ParamValue('mandatory')}))
|
||||
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
|
||||
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
|
||||
descr = OptionDescription('tiram', '', [leadership])
|
||||
cfg = Config(descr)
|
||||
|
@ -5,7 +5,7 @@ do_autopath()
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \
|
||||
IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
|
||||
Params, ParamOption, ParamValue
|
||||
Calculation, Params, ParamOption, ParamValue, calc_value
|
||||
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError
|
||||
from tiramisu.storage import list_sessions
|
||||
from .config import config_type, get_config
|
||||
@ -748,7 +748,11 @@ def test_meta_exception_meta():
|
||||
def test_meta_properties_requires1():
|
||||
opt1 = BoolOption('opt1', 'opt1', False)
|
||||
opt2 = BoolOption('opt2', "")
|
||||
od2 = OptionDescription('od2', "", [opt2], requires=({'option': opt1, 'expected': False, 'action': 'disabled'},))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(opt1, todict=True),
|
||||
'expected': ParamValue(False)}))
|
||||
od2 = OptionDescription('od2', "", [opt2], properties=(disabled_property,))
|
||||
opt3 = BoolOption('opt3', '')
|
||||
opt2.impl_add_consistency('not_equal', opt3)
|
||||
od = OptionDescription('root', '', [opt1, od2, opt3])
|
||||
@ -765,7 +769,12 @@ def test_meta_properties_requires_mandatory():
|
||||
probes = BoolOption('probes', 'probes available', False)
|
||||
eth0_method = ChoiceOption('eth0_method', '', ('static', 'dhcp'), 'static')
|
||||
ip_address = IPOption('ip_address', '')
|
||||
ip_eth0 = IPOption('ip_eth0', "ip", requires=({'option': probes, 'expected': True, 'action': 'mandatory'},), callback=return_condition, callback_params=Params(kwargs={'val': ParamOption(ip_address), 'condition': ParamOption(eth0_method), 'expected': ParamValue('dhcp')}))
|
||||
mandatory_property = Calculation(calc_value,
|
||||
Params(ParamValue('mandatory'),
|
||||
kwargs={'condition': ParamOption(probes),
|
||||
'expected': ParamValue('yes'),
|
||||
'default': ParamValue(None)}))
|
||||
ip_eth0 = IPOption('ip_eth0', "ip", properties=(mandatory_property,), callback=return_condition, callback_params=Params(kwargs={'val': ParamOption(ip_address), 'condition': ParamOption(eth0_method), 'expected': ParamValue('dhcp')}))
|
||||
ip_gw = IPOption('ip_gw', 'gw')
|
||||
ip_gw.impl_add_consistency('not_equal', ip_eth0)
|
||||
od = OptionDescription('root', '', [ip_gw, probes, eth0_method, ip_address, ip_eth0])
|
||||
|
@ -3,13 +3,14 @@ do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from py.test import raises
|
||||
import warnings
|
||||
|
||||
from tiramisu import Config
|
||||
from tiramisu.config import KernelConfig
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
|
||||
undefined, Params, ParamOption, ParamValue, ParamContext, calc_value
|
||||
undefined, Calculation, Params, ParamOption, ParamValue, ParamContext, calc_value
|
||||
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.storage import list_sessions
|
||||
@ -102,11 +103,9 @@ def make_description_duplicates():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
||||
default=False)
|
||||
# dummy2 (same path)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
# dummy3 (same name)
|
||||
@ -123,13 +122,18 @@ def test_identical_paths():
|
||||
"""If in the schema (the option description) there is something that
|
||||
have the same name, an exection is raised
|
||||
"""
|
||||
raises(ConflictError, "make_description_duplicates()")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
raises(ConflictError, "make_description_duplicates()")
|
||||
|
||||
|
||||
def test_hidden_if_in2(config_type):
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1),
|
||||
'default': ParamValue(None)}))
|
||||
stroption = StrOption('str', 'Test string option', default="abc", properties=(hidden_property,))
|
||||
descr = OptionDescription('constraints', '', [stroption, intoption])
|
||||
cfg_ori = Config(descr)
|
||||
cfg_ori.property.read_write()
|
||||
@ -154,8 +158,12 @@ def test_hidden_if_in_with_group(config_type):
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1),
|
||||
'default': ParamValue(None)}))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], properties=(hidden_property,))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg_ori = Config(descr)
|
||||
@ -179,8 +187,12 @@ def test_disabled_with_group():
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1),
|
||||
'default': ParamValue(None)}))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], properties=(disabled_property,))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
@ -201,11 +213,15 @@ def make_description_callback():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(boolop),
|
||||
'expected': ParamValue(True),
|
||||
'default': ParamValue(None)}))
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=(hidden_property,))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
||||
properties=(hidden_property,))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
@ -268,7 +284,7 @@ def test_params():
|
||||
def test_param_option():
|
||||
val1 = StrOption('val1', "")
|
||||
raises(ValueError, "ParamOption('str')")
|
||||
raises(ValueError, "ParamOption(val1, 'str')")
|
||||
raises(AssertionError, "ParamOption(val1, 'str')")
|
||||
|
||||
|
||||
def test_callback_invalid():
|
||||
|
@ -9,7 +9,8 @@ from tiramisu.i18n import _
|
||||
from tiramisu.error import display_list, ConfigError
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, Leadership, Config, undefined
|
||||
StrOption, OptionDescription, Leadership, Config, undefined, \
|
||||
Calculation, Params, ParamOption, ParamValue, ParamIndex, calc_value, calc_value_property_help
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu.storage import list_sessions
|
||||
|
||||
@ -168,8 +169,11 @@ def test_reset_with_multi(config_type):
|
||||
def test_property_only_raises():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", properties=(hidden_property,), multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
@ -231,8 +235,11 @@ def test_access_with_multi_default(config_type):
|
||||
def test_multi_with_requires():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", properties=(hidden_property,), multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
cfg = Config(descr)
|
||||
cfg.property.read_write()
|
||||
@ -242,23 +249,32 @@ def test_multi_with_requires():
|
||||
assert 'hidden' in cfg.forcepermissive.option('str').property.get()
|
||||
|
||||
|
||||
def test__requires_with_inverted():
|
||||
def test_requires_with_inverted():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
|
||||
hide_property = Calculation(calc_value,
|
||||
Params(ParamValue('hide'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", properties=(hide_property,), multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
cfg = Config(descr)
|
||||
assert not 'hidden' in cfg.option('str').property.get()
|
||||
assert 'hide' in cfg.option('str').property.get()
|
||||
cfg.option('int').value.set(1)
|
||||
assert not 'hidden' in cfg.option('str').property.get()
|
||||
assert not 'hide' in cfg.option('str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], properties=(hidden_property,), multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
cfg = Config(descr2)
|
||||
@ -272,8 +288,12 @@ def test_multi_with_requires_in_another_group():
|
||||
def test_multi_with_requires_in_another_group_inverse():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
# requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], properties=(hidden_property,), multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
cfg = Config(descr2)
|
||||
@ -287,8 +307,11 @@ def test_multi_with_requires_in_another_group_inverse():
|
||||
def test_apply_requires_from_config():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], properties=(hidden_property,), multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
cfg = Config(descr2)
|
||||
@ -304,8 +327,11 @@ def test_apply_requires_from_config():
|
||||
def test_apply_requires_with_disabled():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], properties=(disabled_property,), multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
cfg = Config(descr2)
|
||||
@ -321,8 +347,11 @@ def test_apply_requires_with_disabled():
|
||||
def test_multi_with_requires_with_disabled_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(intoption),
|
||||
'expected': ParamValue(1)}))
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], properties=(disabled_property,), multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
cfg = Config(descr2)
|
||||
@ -331,42 +360,54 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
||||
cfg.option('int').value.set(1)
|
||||
raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
|
||||
assert 'disabled' in cfg.unrestraint.option('opt.str').property.get()
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_multi():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("opt", "", [b, c])
|
||||
descr
|
||||
raises(ValueError, "Config(descr)")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_multi_inverse():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
descr = OptionDescription("opt", "", [b, c])
|
||||
descr
|
||||
raises(ValueError, "Config(descr)")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_leadership():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = Leadership("int", "", [b, c])
|
||||
od = OptionDescription('root', '', [descr])
|
||||
Config(od)
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_leadership_leader():
|
||||
b = IntOption('int', 'Test int option', multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
raises(ValueError, "Leadership('str', '', [c, b])")
|
||||
#
|
||||
#
|
||||
#def test_multi_with_requires_that_is_multi():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# hidden_property = Calculation(calc_value,
|
||||
# Params(ParamValue('hidden'),
|
||||
# kwargs={'condition': ParamOption(b),
|
||||
# 'expected': ParamValue(1)}))
|
||||
# c = StrOption('str', 'Test string option', default=['abc'], properties=(hidden_property,), multi=True)
|
||||
# descr = OptionDescription("opt", "", [b, c])
|
||||
# descr
|
||||
# # FIXME: ValueError: requirement mal formés pour l'option "int" ne doit pas être une valeur multiple pour "str"
|
||||
# raises(ValueError, "Config(descr)")
|
||||
#
|
||||
#
|
||||
#def test_multi_with_requires_that_is_multi_inverse():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
# descr = OptionDescription("opt", "", [b, c])
|
||||
# descr
|
||||
# Config(descr)
|
||||
# # FIXME: ValueError: requirement mal formés pour l'option "int" ne doit pas être une valeur multiple pour "str"
|
||||
# raises(ValueError, "Config(descr)")
|
||||
#
|
||||
#
|
||||
#def test_multi_with_requires_that_is_leadership():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
# descr = Leadership("int", "", [b, c])
|
||||
# od = OptionDescription('root', '', [descr])
|
||||
# Config(od)
|
||||
#
|
||||
#
|
||||
#def test_multi_with_requires_that_is_leadership_leader():
|
||||
# b = IntOption('int', 'Test int option', multi=True)
|
||||
# c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
# raises(ValueError, "Leadership('str', '', [c, b])")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_leadership_follower():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(c),
|
||||
'index': ParamIndex(),
|
||||
'expected': ParamValue('1')}))
|
||||
d = StrOption('str1', 'Test string option', properties=(hidden_property,), multi=True)
|
||||
descr = Leadership("int", "", [b, c, d])
|
||||
descr2 = OptionDescription('od', '', [descr])
|
||||
cfg = Config(descr2)
|
||||
@ -392,7 +433,13 @@ def test_multi_with_requires_that_is_leadership_follower():
|
||||
def test_multi_with_requires_that_is_leadership_follower_inverse():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(c),
|
||||
'index': ParamIndex(),
|
||||
'inverse_condition': ParamValue(True),
|
||||
'expected': ParamValue(None)}))
|
||||
d = StrOption('str1', 'Test string option', properties=(hidden_property,), multi=True)
|
||||
descr = Leadership("int", "", [b, c, d])
|
||||
descr2 = OptionDescription('od', '', [descr])
|
||||
cfg = Config(descr2)
|
||||
@ -415,16 +462,22 @@ def test_multi_with_requires_that_is_leadership_follower_inverse():
|
||||
raises(PropertiesOptionError, "cfg.option('int.str1', 1).value.get()")
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_not_same_leadership():
|
||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr1 = Leadership("int", "", [b, c])
|
||||
d = IntOption('int1', 'Test int option', default=[0], multi=True)
|
||||
e = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr2 = Leadership("int1", "", [d, e])
|
||||
descr3 = OptionDescription('val', '', [descr1, descr2])
|
||||
descr3
|
||||
raises(ValueError, "Config(descr3)")
|
||||
#def test_multi_with_requires_that_is_not_same_leadership():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# hidden_property = Calculation(calc_value,
|
||||
# Params(ParamValue('hidden'),
|
||||
# kwargs={'condition': ParamOption(b),
|
||||
# 'index': ParamIndex(),
|
||||
# 'expected': ParamValue(1)}))
|
||||
# c = StrOption('str', 'Test string option', properties=(hidden_property,), multi=True)
|
||||
# #c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
# descr1 = Leadership("int", "", [b, c])
|
||||
# d = IntOption('int1', 'Test int option', default=[0], multi=True)
|
||||
# e = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
# descr2 = Leadership("int1", "", [d, e])
|
||||
# descr3 = OptionDescription('val', '', [descr1, descr2])
|
||||
# descr3
|
||||
# raises(ValueError, "Config(descr3)")
|
||||
|
||||
|
||||
def test_multi_with_bool():
|
||||
@ -606,17 +659,45 @@ def test_pprint():
|
||||
s2 = StrOption("string2", "", default="string")
|
||||
s3 = StrOption("string3", "", default=["string"], default_multi="string", multi=True, properties=('hidden',))
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=[{'option': intoption, 'expected': 2, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 3, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 4, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 1, 'action': 'disabled'},
|
||||
{'option': s2, 'expected': 'string', 'action': 'disabled'}])
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption, todict=True),
|
||||
'expected_0': ParamValue(2),
|
||||
'expected_1': ParamValue(3),
|
||||
'expected_2': ParamValue(4),
|
||||
'inverse_condition': ParamValue(True)}),
|
||||
calc_value_property_help)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition_0': ParamOption(intoption, todict=True),
|
||||
'expected_0': ParamValue(1),
|
||||
'condition_1': ParamOption(s2, todict=True),
|
||||
'expected_1': ParamValue('string')}),
|
||||
calc_value_property_help)
|
||||
stroption = StrOption('str', 'Test string option', default="abc", properties=(hidden_property, disabled_property))
|
||||
# requires=[{'option': intoption, 'expected': 2, 'action': 'hidden', 'inverse': True},
|
||||
# {'option': intoption, 'expected': 3, 'action': 'hidden', 'inverse': True},
|
||||
# {'option': intoption, 'expected': 4, 'action': 'hidden', 'inverse': True},
|
||||
# {'option': intoption, 'expected': 1, 'action': 'disabled'},
|
||||
# {'option': s2, 'expected': 'string', 'action': 'disabled'}])
|
||||
|
||||
val2 = StrOption('val2', "")
|
||||
descr2 = OptionDescription("options", "", [val2], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}])
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(intoption, todict=True),
|
||||
'expected': ParamValue(1)}),
|
||||
calc_value_property_help)
|
||||
descr2 = OptionDescription("options", "", [val2], properties=(hidden_property,))
|
||||
#descr2 = OptionDescription("options", "", [val2], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}])
|
||||
|
||||
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(stroption, todict=True),
|
||||
'expected': ParamValue('2'),
|
||||
'inverse_condition': ParamValue(True)}),
|
||||
calc_value_property_help)
|
||||
val3 = StrOption('val3', "", properties=(hidden_property,))
|
||||
#val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
||||
|
||||
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
|
||||
cfg = Config(descr)
|
||||
|
@ -7,7 +7,8 @@ from .config import config_type, get_config
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
PasswordOption, StrOption, DateOption, OptionDescription, Config
|
||||
PasswordOption, StrOption, DateOption, OptionDescription, Config, \
|
||||
Calculation, Params, ParamOption, ParamValue, calc_value
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu.storage import list_sessions
|
||||
|
||||
@ -26,11 +27,17 @@ def make_description():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': gcoption, 'expected': 'ref', 'action': 'hidden'},))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(gcoption),
|
||||
'expected': ParamValue('ref')}))
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=(hidden_property,))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(gcoption),
|
||||
'expected': ParamValue('framework')}))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': gcoption, 'expected': 'framework', 'action': 'hidden'},))
|
||||
default=False, properties=(hidden_property,))
|
||||
|
||||
# ____________________________________________________________
|
||||
booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False)
|
||||
|
@ -9,8 +9,9 @@ from tiramisu.setting import groups
|
||||
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, ConfigError
|
||||
Leadership, Config, calc_value, Params, ParamOption, Calculation, ParamValue, ParamSelfOption, ParamIndex, \
|
||||
calc_value_property_help
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError, ConfigError, display_list
|
||||
from py.test import raises
|
||||
from tiramisu.storage import list_sessions, delete_session
|
||||
|
||||
@ -54,7 +55,7 @@ def test_properties(config_type):
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
|
||||
|
||||
|
||||
def test_requires(config_type):
|
||||
def test_requires_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -76,7 +77,33 @@ def test_requires(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_callback(config_type):
|
||||
def test_requires(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, todict=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = IPOption('ip_address_service', '',
|
||||
properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
assert not cfg.option('activate_service').option.requires()
|
||||
assert not 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:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_callback_legacy(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'}])
|
||||
@ -98,7 +125,7 @@ def test_requires_callback(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_inverse(config_type):
|
||||
def test_requires_inverse_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}])
|
||||
@ -122,7 +149,35 @@ def test_requires_inverse(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_self(config_type):
|
||||
def test_requires_inverse(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, todict=True),
|
||||
'expected': ParamValue(False),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
cfg.option('activate_service').value.set(True)
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_self_legacy(config_type):
|
||||
a = StrOption('ip_address_service', '',
|
||||
requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a])
|
||||
@ -141,7 +196,29 @@ def test_requires_self(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_with_requires(config_type):
|
||||
def test_requires_self(config_type):
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamSelfOption(),
|
||||
'expected': ParamValue('b')}))
|
||||
a = StrOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a])
|
||||
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:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_with_requires_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -162,7 +239,31 @@ def test_requires_with_requires(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_invalid():
|
||||
def test_requires_with_requires(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue(False)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
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:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_invalid_legacy():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
a
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires='string')")
|
||||
@ -177,7 +278,7 @@ def test_requires_invalid():
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_requires_same_action(config_type):
|
||||
def test_requires_same_action_legacy(config_type):
|
||||
activate_service = BoolOption('activate_service', '', True)
|
||||
activate_service_web = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': activate_service, 'expected': False,
|
||||
@ -223,7 +324,59 @@ def test_requires_same_action(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_same_action_callback(config_type):
|
||||
def test_requires_same_action(config_type):
|
||||
activate_service = BoolOption('activate_service', '', True)
|
||||
new_property = Calculation(calc_value,
|
||||
Params(ParamValue('new'),
|
||||
kwargs={'condition': ParamOption(activate_service, todict=True),
|
||||
'expected': ParamValue(False)}),
|
||||
calc_value_property_help)
|
||||
activate_service_web = BoolOption('activate_service_web', '', True, properties=(new_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(activate_service_web, notraisepropertyerror=True, todict=True),
|
||||
'expected': ParamValue(False)}),
|
||||
calc_value_property_help)
|
||||
ip_address_service_web = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
|
||||
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:
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if config_type == 'tiramisu':
|
||||
assert frozenset(props) == frozenset(['new'])
|
||||
else:
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
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"') + ')'
|
||||
if config_type == 'tiramisu':
|
||||
submsg = '"new" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
|
||||
submsg = '"disabled" (' + str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'activate_service_web', _('property'), submsg)) + ')'
|
||||
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_legacy(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,
|
||||
@ -269,7 +422,7 @@ def test_requires_same_action_callback(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_multiple_requires(config_type):
|
||||
def test_multiple_requires_legacy(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
@ -299,7 +452,40 @@ def test_multiple_requires(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative(config_type):
|
||||
def test_multiple_requires(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected_0': ParamValue('yes'),
|
||||
'expected_1': ParamValue('ok')}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
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:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set('no')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative_legacy(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
@ -327,7 +513,41 @@ def test_multiple_requires_cumulative(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative_inverse(config_type):
|
||||
def test_multiple_requires_cumulative(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue('yes')}))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue('yes')}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property, hidden_property))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
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:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
cfg.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_legacy(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
||||
@ -371,7 +591,59 @@ def test_multiple_requires_cumulative_inverse(config_type):
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_multiple_requires_inverse(config_type):
|
||||
def test_multiple_requires_cumulative_inverse(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue('yes'),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected': ParamValue('yes'),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property, hidden_property))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
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()
|
||||
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
cfg.option('activate_service').value.set('no')
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
if config_type == 'tiramisu':
|
||||
assert set(props) == {'hidden', 'disabled'}
|
||||
else:
|
||||
assert set(props) == {'disabled'}
|
||||
|
||||
|
||||
def test_multiple_requires_inverse_legacy(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
||||
@ -402,7 +674,42 @@ def test_multiple_requires_inverse(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive(config_type):
|
||||
def test_multiple_requires_inverse(config_type):
|
||||
a = StrOption('activate_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a),
|
||||
'expected_0': ParamValue('yes'),
|
||||
'expected_1': ParamValue('ok'),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set('yes')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
cfg.option('activate_service').value.set('ok')
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
cfg.option('activate_service').value.set('no')
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -433,7 +740,44 @@ def test_requires_transitive(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_callback(config_type):
|
||||
def test_requires_transitive(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(disabled_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, raisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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:
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
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_legacy(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'}])
|
||||
@ -464,7 +808,7 @@ def test_requires_transitive_callback(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_unrestraint(config_type):
|
||||
def test_requires_transitive_unrestraint_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -486,7 +830,34 @@ def test_requires_transitive_unrestraint(config_type):
|
||||
assert cfg_ori.unrestraint.option('ip_address_service_web').property.get() == {'disabled'}
|
||||
|
||||
|
||||
def test_requires_transitive_owner(config_type):
|
||||
def test_requires_transitive_unrestraint(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(disabled_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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)
|
||||
#
|
||||
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_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -511,7 +882,38 @@ def test_requires_transitive_owner(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_bis(config_type):
|
||||
def test_requires_transitive_owner(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(disabled_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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
|
||||
cfg.option('ip_address_service_web').value.set('1.1.1.1')
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
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_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
abis = BoolOption('activate_service_bis', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
@ -543,7 +945,46 @@ def test_requires_transitive_bis(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_permissive():
|
||||
def test_requires_transitive_bis(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
abis = BoolOption('activate_service_bis', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(disabled_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, abis, b, d])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
#
|
||||
cfg.option('activate_service_web').value.get()
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
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'])
|
||||
#
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_permissive_legacy():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
|
||||
@ -561,7 +1002,31 @@ def test_requires_transitive_hidden_permissive():
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled(config_type):
|
||||
def test_requires_transitive_hidden_permissive():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(hidden_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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)
|
||||
#
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
|
||||
@ -588,7 +1053,40 @@ def test_requires_transitive_hidden_disabled(config_type):
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_transitive_hidden_disabled_multiple(config_type):
|
||||
def test_requires_transitive_hidden_disabled(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(hidden_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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:
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
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_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'hidden'},
|
||||
@ -651,7 +1149,79 @@ def test_requires_transitive_hidden_disabled_multiple(config_type):
|
||||
del req
|
||||
|
||||
|
||||
def test_requires_not_transitive(config_type):
|
||||
def test_requires_transitive_hidden_disabled_multiple(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(hidden_property, disabled_property))
|
||||
mandatory_property = Calculation(calc_value,
|
||||
Params(ParamValue('mandatory'),
|
||||
kwargs={'condition': ParamOption(b),
|
||||
'expected': ParamValue(False)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(mandatory_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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
|
||||
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 ConfigError as err:
|
||||
req = err
|
||||
error_msg = str(_('unable to carry out a calculation for "{0}", cannot access to option "{1}" because has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), display_list(['hidden', 'disabled'], add_quote=True)))
|
||||
assert req, "ip_address_service_web should raise ConfigError"
|
||||
assert str(req) == error_msg
|
||||
del req
|
||||
#
|
||||
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 ConfigError as err:
|
||||
req = err
|
||||
error_msg = str(_('unable to carry out a calculation for "{0}", cannot access to option "{1}" because has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), display_list(['hidden', 'disabled'], add_quote=True)))
|
||||
assert req, "ip_address_service_web should raise RequirementError"
|
||||
assert str(req) == error_msg
|
||||
del req
|
||||
|
||||
|
||||
def test_requires_not_transitive_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -677,7 +1247,39 @@ def test_requires_not_transitive(config_type):
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_not_transitive_not_same_action(config_type):
|
||||
def test_requires_not_transitive(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(disabled_property,))
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b, notraisepropertyerror=True),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'expected': ParamValue(False)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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:
|
||||
cfg.option('activate_service_web').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
#
|
||||
cfg.option('ip_address_service_web').value.get()
|
||||
|
||||
|
||||
def test_requires_not_transitive_not_same_action_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -706,7 +1308,41 @@ def test_requires_not_transitive_not_same_action(config_type):
|
||||
raises(RequirementError, "cfg.option('ip_address_service_web').value.get()")
|
||||
|
||||
|
||||
def test_requires_None(config_type):
|
||||
def test_requires_not_transitive_not_same_action(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = BoolOption('activate_service_web', '', True, properties=(disabled_property,))
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(b),
|
||||
'expected': ParamValue(False)}))
|
||||
d = IPOption('ip_address_service_web', '', properties=(hidden_property,))
|
||||
od = OptionDescription('service', '', [a, b, d])
|
||||
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(ConfigError, "cfg.option('ip_address_service_web').value.get()")
|
||||
|
||||
|
||||
def test_requires_none_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
|
||||
@ -724,7 +1360,28 @@ def test_requires_None(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled(config_type):
|
||||
def test_requires_none(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(None)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -765,7 +1422,53 @@ def test_requires_multi_disabled(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_callback(config_type):
|
||||
def test_requires_multi_disabled(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition_0': ParamOption(a, notraisepropertyerror=True),
|
||||
'condition_1': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected_0': ParamValue(True),
|
||||
'expected_1': ParamValue(1),
|
||||
'condition_operator': ParamValue('OR')}))
|
||||
c = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
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(True)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set(False)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
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_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -806,7 +1509,7 @@ def test_requires_multi_disabled_callback(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format(config_type):
|
||||
def test_requires_multi_disabled_new_format_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -846,7 +1549,7 @@ def test_requires_multi_disabled_new_format(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_unknown_operator():
|
||||
def test_requires_unknown_operator_legacy():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
raises(ValueError, """IPOption('ip_address_service', '',
|
||||
@ -854,7 +1557,7 @@ def test_requires_unknown_operator():
|
||||
'action': 'disabled', 'operator': 'unknown'}])""")
|
||||
|
||||
|
||||
def test_requires_keys():
|
||||
def test_requires_keys_legacy():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
raises(ValueError, """IPOption('ip_address_service', '',
|
||||
@ -862,7 +1565,7 @@ def test_requires_keys():
|
||||
'action': 'disabled', 'operator': 'and'}])""")
|
||||
|
||||
|
||||
def test_requires_unvalid():
|
||||
def test_requires_unvalid_legacy():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
raises(ValueError, """IPOption('ip_address_service', '',
|
||||
@ -870,7 +1573,7 @@ def test_requires_unvalid():
|
||||
'action': 'disabled', 'operator': 'and'}])""")
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format_and(config_type):
|
||||
def test_requires_multi_disabled_new_format_and_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -910,7 +1613,7 @@ def test_requires_multi_disabled_new_format_and(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_new_format_and_2(config_type):
|
||||
def test_requires_multi_disabled_new_format_and_2_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -955,7 +1658,7 @@ def test_requires_multi_disabled_new_format_and_2(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled', 'expert'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse(config_type):
|
||||
def test_requires_multi_disabled_inverse_legacy(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
@ -1003,7 +1706,60 @@ def test_requires_multi_disabled_inverse(config_type):
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled_2(config_type):
|
||||
def test_requires_multi_disabled_inverse(config_type):
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition_0': ParamOption(a, notraisepropertyerror=True),
|
||||
'condition_1': ParamOption(b, notraisepropertyerror=True),
|
||||
'expected_0': ParamValue(True),
|
||||
'expected_1': ParamValue(1),
|
||||
'condition_operator': ParamValue('OR'),
|
||||
'inverse_condition_0': ParamValue(True),
|
||||
'inverse_condition_1': ParamValue(True)}))
|
||||
c = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set(True)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set(False)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('num_service').value.set(1)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('ip_address_service').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
cfg.option('activate_service').value.set(True)
|
||||
cfg.option('ip_address_service').value.get()
|
||||
|
||||
|
||||
def test_requires_multi_disabled_2_legacy(config_type):
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
@ -1051,7 +1807,60 @@ def test_requires_multi_disabled_2(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse_2(config_type):
|
||||
def test_requires_multi_disabled_2(config_type):
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
d = BoolOption('d', '')
|
||||
e = BoolOption('e', '')
|
||||
f = BoolOption('f', '')
|
||||
g = BoolOption('g', '')
|
||||
h = BoolOption('h', '')
|
||||
i = BoolOption('i', '')
|
||||
j = BoolOption('j', '')
|
||||
k = BoolOption('k', '')
|
||||
l = BoolOption('l', '')
|
||||
m = BoolOption('m', '')
|
||||
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
||||
requires = []
|
||||
kwargs={'expected': ParamValue(True),
|
||||
'condition_operator': ParamValue('OR')}
|
||||
for idx, boo in enumerate(list_bools):
|
||||
kwargs['condition_{}'.format(idx)] = ParamOption(boo, notraisepropertyerror=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs=kwargs))
|
||||
z = IPOption('z', '', properties=(disabled_property,))
|
||||
y = copy(list_bools)
|
||||
y.append(z)
|
||||
od = OptionDescription('service', '', y)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
cfg.option('z').value.get()
|
||||
for boo in list_bools:
|
||||
cfg.option(boo.impl_getname()).value.set(True)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
cfg.option(boo.impl_getname()).value.set(False)
|
||||
if boo == m:
|
||||
cfg.option('z').value.get()
|
||||
else:
|
||||
props = []
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_multi_disabled_inverse_2_legacy(config_type):
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
@ -1105,7 +1914,84 @@ def test_requires_multi_disabled_inverse_2(config_type):
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
|
||||
|
||||
def test_requires_requirement_append(config_type):
|
||||
def test_requires_multi_disabled_inverse_2(config_type):
|
||||
a = BoolOption('a', '')
|
||||
b = BoolOption('b', '')
|
||||
c = BoolOption('c', '')
|
||||
d = BoolOption('d', '')
|
||||
e = BoolOption('e', '')
|
||||
f = BoolOption('f', '')
|
||||
g = BoolOption('g', '')
|
||||
h = BoolOption('h', '')
|
||||
i = BoolOption('i', '')
|
||||
j = BoolOption('j', '')
|
||||
k = BoolOption('k', '')
|
||||
l = BoolOption('l', '')
|
||||
m = BoolOption('m', '')
|
||||
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
||||
requires = []
|
||||
kwargs={'expected': ParamValue(True),
|
||||
'condition_operator': ParamValue('OR')}
|
||||
for idx, boo in enumerate(list_bools):
|
||||
kwargs['condition_{}'.format(idx)] = ParamOption(boo, notraisepropertyerror=True)
|
||||
kwargs['inverse_condition_{}'.format(idx)] = ParamValue(True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs=kwargs))
|
||||
#for boo in list_bools:
|
||||
# requires.append({'option': boo, 'expected': True, 'action': 'disabled',
|
||||
# 'inverse': True})
|
||||
z = IPOption('z', '', properties=(disabled_property,))
|
||||
y = copy(list_bools)
|
||||
y.append(z)
|
||||
od = OptionDescription('service', '', y)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
|
||||
props = []
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
for boo in list_bools:
|
||||
cfg.option(boo.impl_getname()).value.set(True)
|
||||
if boo != m:
|
||||
# it's disabled until last option is modified
|
||||
props = []
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.option('z').value.get()
|
||||
for boo in list_bools:
|
||||
cfg.option(boo.impl_getname()).value.set(False)
|
||||
props = []
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
for boo in reversed(list_bools):
|
||||
cfg.option(boo.impl_getname()).value.set(True)
|
||||
if boo != a:
|
||||
# it's disabled until last option is modified
|
||||
props = []
|
||||
try:
|
||||
cfg.option('z').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert frozenset(props) == frozenset(['disabled'])
|
||||
cfg.option('z').value.get()
|
||||
|
||||
|
||||
def test_requires_requirement_append_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -1117,7 +2003,7 @@ def test_requires_requirement_append(config_type):
|
||||
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')")
|
||||
#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
|
||||
@ -1126,7 +2012,31 @@ def test_requires_requirement_append(config_type):
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.add("test")
|
||||
|
||||
|
||||
def test_requires_different_inverse(config_type):
|
||||
def test_requires_requirement_append(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
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
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
cfg_ori.unrestraint.option('ip_address_service').property.add("test")
|
||||
|
||||
|
||||
def test_requires_different_inverse_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '', requires=[
|
||||
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
|
||||
@ -1140,7 +2050,27 @@ def test_requires_different_inverse(config_type):
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
|
||||
|
||||
def test_requires_different_inverse_unicode(config_type):
|
||||
def test_requires_different_inverse(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition_0': ParamOption(a, notraisepropertyerror=True),
|
||||
'condition_1': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected_0': ParamValue(True),
|
||||
'expected_1': ParamValue(True),
|
||||
'condition_operator': ParamValue('OR'),
|
||||
'inverse_condition_0': ParamValue(True)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
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_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
d = StrOption('activate_other_service', '', 'val2')
|
||||
b = IPOption('ip_address_service', '', requires=[
|
||||
@ -1161,7 +2091,34 @@ def test_requires_different_inverse_unicode(config_type):
|
||||
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
|
||||
|
||||
|
||||
def test_requires_recursive_path(config_type):
|
||||
def test_requires_different_inverse_unicode(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
d = StrOption('activate_other_service', '', 'val2')
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition_0': ParamOption(a, notraisepropertyerror=True),
|
||||
'condition_1': ParamOption(d, notraisepropertyerror=True),
|
||||
'expected_0': ParamValue(True),
|
||||
'expected_1': ParamValue('val1'),
|
||||
'condition_operator': ParamValue('OR'),
|
||||
'inverse_condition_0': ParamValue(True)}))
|
||||
b = IPOption('ip_address_service', '', properties=(disabled_property,))
|
||||
od = OptionDescription('service', '', [a, d, 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('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_legacy(config_type):
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
@ -1176,28 +2133,38 @@ def test_requires_recursive_path(config_type):
|
||||
raises(RequirementError, "cfg.option('service.a').value.get()")
|
||||
|
||||
|
||||
def test_optiondescription_requires():
|
||||
def test_optiondescription_requires_legacy():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('ip_address_service', '', multi=True)
|
||||
a, b
|
||||
OptionDescription('service', '', [b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
|
||||
|
||||
def test_optiondescription_requires_multi():
|
||||
def test_optiondescription_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('ip_address_service', '', multi=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(a, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False)}))
|
||||
OptionDescription('service', '', [b], properties=(disabled_property,))
|
||||
|
||||
|
||||
def test_optiondescription_requires_multi_legacy():
|
||||
# FIXME not legacy !!!
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '', multi=True)
|
||||
a, b
|
||||
raises(ValueError, "OptionDescription('service', '', [a], requires=[{'option': b, 'expected': False, 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_properties_conflict():
|
||||
def test_properties_conflict_legacy():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
a
|
||||
raises(ValueError, "IPOption('ip_address_service', '', properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
||||
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_leadership_requires(config_type):
|
||||
def test_leadership_requires_legacy(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'}])
|
||||
@ -1248,7 +2215,63 @@ def test_leadership_requires(config_type):
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_leadership_requires_callback(config_type):
|
||||
def test_leadership_requires(config_type):
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(ip_admin_eth0, notraisepropertyerror=True),
|
||||
'expected': ParamValue('192.168.1.1'),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'index': ParamIndex()}))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
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']
|
||||
#
|
||||
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()")
|
||||
#
|
||||
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']}
|
||||
#
|
||||
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
|
||||
assert ret['ip_admin_eth0.netmask_admin_eth0'][0] is None
|
||||
assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError)
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][1]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
#
|
||||
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
|
||||
assert ret['ip_admin_eth0.netmask_admin_eth0'][0] == '255.255.255.255'
|
||||
assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError)
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][1]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_leadership_requires_callback_legacy(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'}])
|
||||
@ -1299,7 +2322,8 @@ def test_leadership_requires_callback(config_type):
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_leadership_requires_both():
|
||||
def test_leadership_requires_both_legacy():
|
||||
# FIXME ne devrait pas pouvoir mettre de propriété calculé sur une master ...
|
||||
ip_admin = StrOption('ip_admin_eth0', "ip réseau autorisé")
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
@ -1307,7 +2331,7 @@ def test_leadership_requires_both():
|
||||
raises(RequirementError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_leadership_requires_properties_invalid():
|
||||
def test_leadership_requires_properties_invalid_legacy():
|
||||
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
|
||||
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,
|
||||
@ -1315,16 +2339,7 @@ def test_leadership_requires_properties_invalid():
|
||||
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',), requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_leadership_requires_properties_invalid_2():
|
||||
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
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'}])
|
||||
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',))")
|
||||
|
||||
|
||||
def test_leadership_requires_properties():
|
||||
def test_leadership_requires_properties_legacy():
|
||||
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
|
||||
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,
|
||||
@ -1333,7 +2348,7 @@ def test_leadership_requires_properties():
|
||||
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
||||
|
||||
|
||||
def test_leadership_requires_leader(config_type):
|
||||
def test_leadership_requires_leader_legacy(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'}])
|
||||
@ -1362,7 +2377,40 @@ def test_leadership_requires_leader(config_type):
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_leader_callback(config_type):
|
||||
def test_leadership_requires_leader(config_type):
|
||||
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(activate, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'index': ParamIndex()}))
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=(disabled_property,))
|
||||
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])
|
||||
od = OptionDescription('toto', '', [activate, interface1])
|
||||
cfg = Config(od)
|
||||
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(['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)
|
||||
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()")
|
||||
#
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
#
|
||||
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_legacy(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'}])
|
||||
@ -1391,7 +2439,7 @@ def test_leadership_requires_leader_callback(config_type):
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_leadership(config_type):
|
||||
def test_leadership_requires_leadership_legacy(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)
|
||||
@ -1424,7 +2472,44 @@ def test_leadership_requires_leadership(config_type):
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_leadership_callback(config_type):
|
||||
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)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(activate, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'index': ParamIndex()}))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=(disabled_property,))
|
||||
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)
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
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()")
|
||||
#
|
||||
cfg.option('activate').value.set(True)
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
#
|
||||
cfg.option('activate').value.set(False)
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
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_legacy(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)
|
||||
@ -1453,7 +2538,7 @@ def test_leadership_requires_leadership_callback(config_type):
|
||||
assert cfg.value.dict() == {'activate': False}
|
||||
|
||||
|
||||
def test_leadership_requires_no_leader(config_type):
|
||||
def test_leadership_requires_no_leader_legacy(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,
|
||||
@ -1483,7 +2568,41 @@ def test_leadership_requires_no_leader(config_type):
|
||||
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(config_type):
|
||||
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)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(activate, notraisepropertyerror=True),
|
||||
'expected': ParamValue(False),
|
||||
'index': ParamIndex()}))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,))
|
||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
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()")
|
||||
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_legacy(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,
|
||||
@ -1518,7 +2637,7 @@ def test_leadership_requires_no_leader_callback(config_type):
|
||||
del dico['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
|
||||
|
||||
def test_leadership_requires_complet(config_type):
|
||||
def test_leadership_requires_complet_legacy(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Unicode")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
@ -1606,7 +2725,107 @@ def test_leadership_requires_complet(config_type):
|
||||
del dico['options.unicode.unicode7']
|
||||
|
||||
|
||||
def test_leadership_requires_complet_callback(config_type):
|
||||
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)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(option, notraisepropertyerror=True),
|
||||
'expected': ParamValue('test'),
|
||||
'index': ParamIndex(),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option3 = StrOption('unicode3', "Unicode follower 3", properties=(hidden_property,), multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(option2, notraisepropertyerror=True),
|
||||
'expected': ParamValue('test'),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'index': ParamIndex(),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option4 = StrOption('unicode4', "Unicode follower 4", properties=(hidden_property,), multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition': ParamOption(optiontoto, notraisepropertyerror=True),
|
||||
'expected': ParamValue('test'),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option5 = StrOption('unicode5', "Unicode follower 5", properties=(hidden_property,), multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition_0': ParamOption(optiontoto, notraisepropertyerror=True),
|
||||
'expected_0': ParamValue('test'),
|
||||
'condition_1': ParamOption(option2, notraisepropertyerror=True),
|
||||
'expected_1': ParamValue('test'),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'index': ParamIndex(),
|
||||
'condition_operator': ParamValue('OR'),
|
||||
'inverse_condition_0': ParamValue(True),
|
||||
'inverse_condition_1': ParamValue(True)}))
|
||||
option6 = StrOption('unicode6', "Unicode follower 6", properties=(hidden_property,), multi=True)
|
||||
hidden_property = Calculation(calc_value,
|
||||
Params(ParamValue('hidden'),
|
||||
kwargs={'condition_0': ParamOption(option2, notraisepropertyerror=True),
|
||||
'expected_0': ParamValue('test'),
|
||||
'condition_1': ParamOption(optiontoto, notraisepropertyerror=True),
|
||||
'expected_1': ParamValue('test'),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'index': ParamIndex(),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option7 = StrOption('unicode7', "Unicode follower 7", properties=(hidden_property,), multi=True)
|
||||
descr1 = Leadership("unicode", "Common configuration 1",
|
||||
[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])
|
||||
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]
|
||||
assert dico['options.unicode.unicode2'] == ['test', None]
|
||||
assert dico['options.unicode.unicode3'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode4'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert dico['options.unicodetoto'] is None
|
||||
del dico['options.unicode.unicode3'][1]
|
||||
del dico['options.unicode.unicode3']
|
||||
del dico['options.unicode.unicode4'][1]
|
||||
del dico['options.unicode.unicode4']
|
||||
#
|
||||
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]
|
||||
assert dico['options.unicode.unicode2'] == ['test', None]
|
||||
assert dico['options.unicode.unicode3'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode4'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode5'] == [None, None]
|
||||
assert dico['options.unicode.unicode6'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode6'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode7'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode7'][1], PropertiesOptionError)
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
del dico['options.unicode.unicode3'][1]
|
||||
del dico['options.unicode.unicode3']
|
||||
del dico['options.unicode.unicode4'][1]
|
||||
del dico['options.unicode.unicode4']
|
||||
del dico['options.unicode.unicode6'][1]
|
||||
del dico['options.unicode.unicode6']
|
||||
del dico['options.unicode.unicode7'][1]
|
||||
del dico['options.unicode.unicode7']
|
||||
|
||||
|
||||
def test_leadership_requires_complet_callback_legacy(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Unicode leader")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
@ -1707,7 +2926,7 @@ def test_leadership_requires_complet_callback(config_type):
|
||||
del dico['options.unicode.unicode7']
|
||||
|
||||
|
||||
def test_leadership_requires_transitive1(config_type):
|
||||
def test_leadership_requires_transitive1_legacy(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Simple unicode")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
@ -1823,7 +3042,128 @@ def test_leadership_requires_transitive1(config_type):
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
|
||||
|
||||
def test_leadership_requires_transitive_callback(config_type):
|
||||
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)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(optiontoto, raisepropertyerror=True),
|
||||
'expected': ParamValue('test'),
|
||||
'index': ParamIndex(),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option2 = StrOption('unicode2', "Unicode follower 2", properties=(disabled_property,), multi=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(option2, raisepropertyerror=True),
|
||||
'expected': ParamValue('test'),
|
||||
'index': ParamIndex(),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option3 = StrOption('unicode3', "Unicode follower 3", properties=(disabled_property,), multi=True)
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(option3, raisepropertyerror=True),
|
||||
'expected': ParamValue('test'),
|
||||
'index': ParamIndex(),
|
||||
'no_condition_is_invalid': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
option4 = StrOption('unicode4', "Unicode follower 4", properties=(disabled_property,), multi=True)
|
||||
descr1 = Leadership("unicode", "Common configuration 1",
|
||||
[option, option1, option2, option3, option4])
|
||||
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
|
||||
descr = OptionDescription("unicode1", "", [descr])
|
||||
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}
|
||||
#
|
||||
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'}
|
||||
#
|
||||
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']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert dico['options.unicode.unicode2'] == [None, None, None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
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']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert dico['options.unicode.unicode2'] == [None, 'test', None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode3'][1] == 'test'
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode4'][1] == None
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
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']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert dico['options.unicode.unicode2'] == [None, 'rah', None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
#
|
||||
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']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
|
||||
|
||||
def test_leadership_requires_transitive_callback_legacy(config_type):
|
||||
optiontoto = StrOption('unicodetoto', "Unicode leader")
|
||||
option = StrOption('unicode', "Unicode leader", multi=True)
|
||||
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
|
||||
@ -1943,3 +3283,8 @@ def test_leadership_requires_transitive_callback(config_type):
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
|
||||
|
||||
# FIXME tester l'ajout d'un Calculation
|
||||
# FIXME permissive peut etre in calcul !
|
||||
# FIXME Calculation sur des multis ...
|
||||
|
@ -1,9 +1,8 @@
|
||||
#from autopath import do_autopath
|
||||
#do_autopath()
|
||||
#
|
||||
from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \
|
||||
OptionDescription, DynOptionDescription
|
||||
from tiramisu import Config
|
||||
from tiramisu import BoolOption, UnicodeOption, SymLinkOption, OptionDescription, DynOptionDescription, \
|
||||
Calculation, Params, ParamOption, ParamValue, calc_value, Config
|
||||
from pickle import dumps
|
||||
from py.test import raises
|
||||
import sys
|
||||
@ -213,7 +212,12 @@ def _diff_conf(cfg1, cfg2):
|
||||
|
||||
def test_diff_opt():
|
||||
b = BoolOption('b', '')
|
||||
u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(b),
|
||||
'expected': ParamValue(True),
|
||||
'inverse_condition': ParamValue(True)}))
|
||||
u = UnicodeOption('u', '', properties=(disabled_property,))
|
||||
s = SymLinkOption('s', u)
|
||||
o = OptionDescription('o', '', [b, u, s])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
|
@ -5,7 +5,7 @@ do_autopath()
|
||||
from .config import config_type, get_config
|
||||
|
||||
from tiramisu import BoolOption, StrOption, SymLinkOption, \
|
||||
OptionDescription, Leadership, Config
|
||||
OptionDescription, Leadership, Config, Calculation, calc_value, Params, ParamOption, ParamValue
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.storage import list_sessions
|
||||
@ -122,9 +122,11 @@ def test_symlink_getcallback():
|
||||
|
||||
def test_symlink_requires(config_type):
|
||||
boolopt = BoolOption('b', '', default=True)
|
||||
stropt = StrOption('s', '', requires=[{'option': boolopt,
|
||||
'expected': False,
|
||||
'action': 'disabled'}])
|
||||
disabled_property = Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(boolopt),
|
||||
'expected': ParamValue(False)}))
|
||||
stropt = StrOption('s', '', properties=(disabled_property,))
|
||||
linkopt = SymLinkOption("c", stropt)
|
||||
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
|
||||
cfg = Config(descr)
|
||||
|
Reference in New Issue
Block a user