add tests
This commit is contained in:
parent
2b479bb983
commit
9ffd2e6505
@ -3,8 +3,8 @@ from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
|
||||
OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \
|
||||
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \
|
||||
IPOption, OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \
|
||||
Params, ParamOption, ParamValue
|
||||
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError, APIError
|
||||
from tiramisu.storage import list_sessions
|
||||
@ -22,6 +22,12 @@ def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def return_condition(val, condition, expected):
|
||||
if condition == expected:
|
||||
return val
|
||||
return None
|
||||
|
||||
|
||||
def raise_exception():
|
||||
raise Exception('test')
|
||||
|
||||
@ -678,6 +684,28 @@ def test_meta_exception_meta():
|
||||
raises(Exception, "conf1.make_dict()")
|
||||
|
||||
|
||||
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')}))
|
||||
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])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf1.property.read_write()
|
||||
meta = MetaConfig([conf1], 'meta')
|
||||
#
|
||||
meta.option('probes').value.set(True)
|
||||
meta.option('ip_address').value.set('1.1.1.1')
|
||||
meta.option('ip_gw').value.set('1.1.1.2')
|
||||
conf1.option('eth0_method').value.set('dhcp')
|
||||
conf1.property.read_only()
|
||||
meta._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
conf1._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
assert conf1.value.dict(fullpath=True) == {'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1', 'ip_gw': '1.1.1.2'}
|
||||
|
||||
|
||||
def test_meta_callback():
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
|
||||
|
Loading…
Reference in New Issue
Block a user