2015-07-26 18:55:21 +02:00
|
|
|
# coding: utf-8
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
2019-06-21 23:04:04 +02:00
|
|
|
# FIXME from .config import config_type, get_config
|
2013-04-16 22:44:16 +02:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
2018-08-14 22:15:40 +02:00
|
|
|
from tiramisu import Config
|
2019-12-08 09:09:48 +01:00
|
|
|
from tiramisu import IntOption, StrOption, OptionDescription, \
|
2019-09-01 09:41:53 +02:00
|
|
|
SymLinkOption, Leadership, undefined, Calculation, Params, \
|
|
|
|
ParamOption, ParamValue, calc_value
|
2015-10-29 09:03:13 +01:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConfigError
|
2015-07-26 18:55:21 +02:00
|
|
|
from tiramisu.setting import groups
|
2018-10-31 08:00:19 +01:00
|
|
|
from tiramisu.storage import list_sessions
|
|
|
|
|
|
|
|
|
|
|
|
def teardown_function(function):
|
|
|
|
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def make_description():
|
2018-09-08 22:51:27 +02:00
|
|
|
stro = StrOption('str', '')
|
|
|
|
subdescr = OptionDescription('sub', '', [stro], properties=('disabled',))
|
2013-04-16 22:44:16 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option',
|
|
|
|
properties=('mandatory', ))
|
2019-12-08 09:09:48 +01:00
|
|
|
stroption2 = StrOption('unicode2', 'Test string option',
|
2013-04-20 11:25:14 +02:00
|
|
|
properties=('mandatory', ))
|
2013-04-16 22:44:16 +02:00
|
|
|
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
|
|
|
properties=('mandatory', ))
|
2019-12-08 09:09:48 +01:00
|
|
|
descr = OptionDescription('tiram', '', [subdescr, stroption, stroption1, stroption2, stroption3])
|
2013-04-16 22:44:16 +02:00
|
|
|
return descr
|
|
|
|
|
|
|
|
|
2015-10-29 09:03:13 +01:00
|
|
|
def return_value(value):
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def make_description2():
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option',
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption2 = SymLinkOption('unicode2', stroption1)
|
|
|
|
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
|
|
|
properties=('mandatory', ))
|
2019-12-08 09:09:48 +01:00
|
|
|
unicode1 = StrOption('unicode1', 'Test string option', Calculation(return_value, Params(ParamOption(stroption))), properties=('mandatory',))
|
2015-10-29 09:03:13 +01:00
|
|
|
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def make_description_sym():
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option',
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption2 = SymLinkOption('unicode2', stroption1)
|
|
|
|
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
|
|
|
properties=('mandatory', ))
|
|
|
|
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def make_description3():
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option',
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption2 = SymLinkOption('unicode2', stroption1)
|
|
|
|
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
|
|
|
properties=('mandatory', ))
|
2019-12-08 09:09:48 +01:00
|
|
|
unicode1 = StrOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
|
2018-04-15 21:13:16 +02:00
|
|
|
int1 = IntOption('int1', '', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
|
2015-10-29 09:03:13 +01:00
|
|
|
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_ro():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str1').value.set('yes')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('str1').value.get() == 'yes'
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_ro_dict():
|
2018-12-07 23:33:54 +01:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
2018-12-07 23:33:54 +01:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.value.dict()
|
2018-12-07 23:33:54 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str1').value.set('yes')
|
|
|
|
await cfg.option('unicode2').value.set('yes')
|
|
|
|
await cfg.property.read_only()
|
2018-12-07 23:33:54 +01:00
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.value.dict()
|
2018-12-07 23:33:54 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str3').value.set(['yes'])
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'unicode2': 'yes'}
|
2018-12-07 23:33:54 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_rw():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_write()
|
2018-12-07 23:33:54 +01:00
|
|
|
# not mandatory in rw
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.get()
|
|
|
|
await cfg.option('str1').value.set('yes')
|
|
|
|
assert await cfg.option('str1').value.get() == 'yes'
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_default():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
#not mandatory in rw
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str').value.get()
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.set('yes')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.set(None)
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_delete():
|
2015-12-17 22:41:57 +01:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
|
|
|
await cfg.option('str').value.get()
|
2015-12-17 22:41:57 +01:00
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.get()
|
2015-12-17 22:41:57 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str1').value.set('yes')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('str1').value.get() == 'yes'
|
|
|
|
await cfg.property.pop('everything_frozen')
|
2015-12-17 22:41:57 +01:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.reset()
|
2015-12-17 22:41:57 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str').value.reset()
|
2018-03-19 08:33:53 +01:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
assert await cfg.option('str1').value.get() == 'yes'
|
2015-12-17 22:41:57 +01:00
|
|
|
|
|
|
|
|
2013-04-16 22:44:16 +02:00
|
|
|
#valeur vide : None, '', u'', ...
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_none():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str1').value.set(None)
|
|
|
|
assert await cfg.option('str1').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_empty():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str1').value.set('')
|
|
|
|
assert await cfg.option('str1').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_multi_none():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str3').value.set([None])
|
|
|
|
assert await cfg.option('str3').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str3').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str3').value.set(['yes', None])
|
|
|
|
assert await cfg.option('str3').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str3').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_multi_empty():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str3').value.set([])
|
|
|
|
assert await cfg.option('str3').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2015-04-20 14:49:43 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str3').value.get()
|
2015-04-20 14:49:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str3').value.set([''])
|
|
|
|
assert await cfg.option('str3').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str3').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2015-04-20 14:49:43 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str3').value.set(['yes', ''])
|
|
|
|
assert await cfg.option('str3').owner.get() == 'user'
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str3').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
2015-04-20 14:49:43 +02:00
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_multi_append():
|
2013-04-17 21:33:34 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str3').value.set(['yes'])
|
|
|
|
await cfg.property.read_write()
|
|
|
|
ret = await cfg.option('str3').value.get()
|
|
|
|
ret.append(None)
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_disabled():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str1').value.get()
|
|
|
|
await cfg.option('str1').property.add('disabled')
|
|
|
|
await cfg.property.read_only()
|
2018-03-19 08:33:53 +01:00
|
|
|
pop = []
|
2013-04-16 22:44:16 +02:00
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
2019-06-21 23:04:04 +02:00
|
|
|
search_prop = {'disabled'}
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(prop) == search_prop
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_unicode():
|
2013-04-17 22:06:10 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('unicode2').value.get()
|
|
|
|
await cfg.property.read_only()
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('unicode2').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('unicode2').value.set(u'')
|
|
|
|
await cfg.property.read_only()
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('unicode2').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert 'mandatory' in prop
|
2013-04-17 22:06:10 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_ro():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
proc = []
|
|
|
|
try:
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('str').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2018-03-19 08:33:53 +01:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2019-12-24 15:24:20 +01:00
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.set('a')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_rw():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
|
|
|
|
await cfg.option('str').value.set('a')
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_disabled():
|
2013-04-16 22:44:16 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
|
|
|
await cfg.option('str').property.add('disabled')
|
|
|
|
assert set(await cfg.value.mandatory()) == {'str1', 'unicode2', 'str3'}
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_hidden():
|
2014-10-26 16:39:24 +01:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.permissive.add('hidden')
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
|
|
|
await cfg.option('str').property.add('hidden')
|
|
|
|
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_frozen():
|
2013-04-17 21:33:34 +02:00
|
|
|
descr = make_description()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
|
|
|
await cfg.option('str').property.add('frozen')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_leader():
|
2015-07-26 18:55:21 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
|
|
|
properties=('mandatory', ))
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
|
|
|
multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('o', '', [interface1])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.value.dict()
|
2015-07-26 18:55:21 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_leader():
|
2016-06-29 21:42:54 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
|
|
|
properties=('mandatory', ))
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
|
|
|
multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('o', '', [interface1])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
|
2016-06-29 21:42:54 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_leader_empty():
|
2015-07-26 18:55:21 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
|
|
|
multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('o', '', [interface1])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_write()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
2015-07-26 18:55:21 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
|
|
|
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
|
|
await cfg.property.read_only()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
2015-07-26 18:55:21 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
|
|
|
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
|
|
await cfg.property.read_only()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
|
|
|
await cfg.property.read_write()
|
2015-07-26 18:55:21 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
|
|
|
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
2017-05-06 19:54:20 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
|
|
|
|
await cfg.property.read_only()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
2015-07-26 18:55:21 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_leader_empty():
|
2016-06-29 21:42:54 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
|
|
|
multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('o', '', [interface1])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
|
|
|
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
|
|
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
2016-06-29 21:42:54 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
|
|
|
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
|
|
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
|
2016-06-29 21:42:54 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
|
|
|
assert list(await cfg.value.mandatory()) == []
|
2016-06-29 21:42:54 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_follower():
|
2015-07-26 18:55:21 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
|
|
|
multi=True, properties=('mandatory', ))
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('o', '', [interface1])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
|
|
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [],
|
|
|
|
'ip_admin_eth0.netmask_admin_eth0': []}
|
2015-07-26 18:55:21 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
2015-07-26 18:55:21 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
|
|
|
#
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
|
|
|
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
|
|
|
|
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip'],
|
|
|
|
'ip_admin_eth0.netmask_admin_eth0': ['ip']}
|
2015-10-29 09:03:13 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_follower():
|
2016-06-29 21:42:54 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
|
|
|
multi=True, properties=('mandatory', ))
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('o', '', [interface1])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
2016-06-29 21:42:54 +02:00
|
|
|
#
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.property.read_write()
|
|
|
|
assert list(await cfg.value.mandatory()) == []
|
|
|
|
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
|
|
|
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
|
2016-06-29 21:42:54 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_symlink():
|
2015-10-29 09:03:13 +01:00
|
|
|
descr = make_description_sym()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'str3']
|
|
|
|
await cfg.option('str').property.add('frozen')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'str3']
|
|
|
|
|
|
|
|
|
|
|
|
#@pytest.mark.asyncio
|
|
|
|
#async def test_mandatory_warnings_validate():
|
2018-03-19 08:33:53 +01:00
|
|
|
# descr = make_description3()
|
2019-12-24 15:24:20 +01:00
|
|
|
# cfg = await Config(descr)
|
|
|
|
# await cfg.option('str').value.set('')
|
|
|
|
# raises(ValueError, "list(await cfg.value.mandatory())")
|
|
|
|
# await cfg.option('str').value.set('test')
|
|
|
|
# raises(ValueError, "list(await cfg.value.mandatory())")
|
2015-10-29 09:03:13 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_validate_empty():
|
2015-10-29 09:03:13 +01:00
|
|
|
descr = make_description2()
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'str3']
|
2015-10-29 09:03:13 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_requires():
|
2018-04-06 16:09:10 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option',
|
|
|
|
properties=('mandatory', ))
|
2019-12-08 09:09:48 +01:00
|
|
|
stroption2 = StrOption('unicode2', 'Test string option',
|
2018-04-06 16:09:10 +02:00
|
|
|
properties=('mandatory', ))
|
2019-09-01 09:41:53 +02:00
|
|
|
mandatory_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('mandatory'),
|
|
|
|
kwargs={'condition': ParamOption(stroption, notraisepropertyerror=True),
|
|
|
|
'expected': ParamValue('yes'),
|
|
|
|
'no_condition_is_invalid': ParamValue(True)}))
|
|
|
|
stroption3 = StrOption('str3', 'Test string option', multi=True, properties=(mandatory_property,))
|
2018-04-06 16:09:10 +02:00
|
|
|
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.get()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.option('str').value.set('yes')
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_requires_leadership():
|
2018-04-06 16:09:10 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option', multi=True)
|
2019-09-01 09:41:53 +02:00
|
|
|
mandatory_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue(None),
|
|
|
|
kwargs={'condition': ParamOption(stroption),
|
|
|
|
'expected': ParamValue('yes'),
|
2019-12-08 09:09:48 +01:00
|
|
|
'reverse_condition': ParamValue(True),
|
2019-09-01 09:41:53 +02:00
|
|
|
'default': ParamValue('mandatory')}))
|
|
|
|
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
|
2019-02-23 19:06:23 +01:00
|
|
|
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
|
|
|
|
descr = OptionDescription('tiram', '', [stroption, leadership])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('str').value.set('')
|
|
|
|
await cfg.option('leader.str1').value.set(['str'])
|
|
|
|
assert list(await cfg.value.mandatory()) == ['str']
|
|
|
|
await cfg.option('str').value.set('yes')
|
|
|
|
assert list(await cfg.value.mandatory()) == ['leader.str2']
|
2018-04-06 16:09:10 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_warnings_requires_leadership_follower():
|
2018-04-06 16:09:10 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', multi=True)
|
|
|
|
stroption1 = StrOption('str1', 'Test string option', multi=True)
|
2019-09-01 09:41:53 +02:00
|
|
|
mandatory_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue(None),
|
|
|
|
kwargs={'condition': ParamOption(stroption1),
|
|
|
|
'expected': ParamValue('yes'),
|
2019-12-08 09:09:48 +01:00
|
|
|
'reverse_condition': ParamValue(True),
|
2019-09-01 09:41:53 +02:00
|
|
|
'default': ParamValue('mandatory')}))
|
|
|
|
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
|
2019-02-23 19:06:23 +01:00
|
|
|
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
|
|
|
|
descr = OptionDescription('tiram', '', [leadership])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.option('leader.str').value.set(['str'])
|
|
|
|
assert list(await cfg.value.mandatory()) == []
|
|
|
|
await cfg.option('leader.str1', 0).value.set('yes')
|
|
|
|
assert list(await cfg.value.mandatory()) == ['leader.str2']
|
2018-04-06 16:09:10 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mandatory_od_disabled():
|
2015-10-29 09:03:13 +01:00
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('od', '', [descr])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(descr)
|
|
|
|
await cfg.property.read_only()
|
|
|
|
assert list(await cfg.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
|
|
|
await cfg.option('tiram').property.add('disabled')
|
|
|
|
assert list(await cfg.value.mandatory()) == []
|