tiramisu/tests/test_duplicate_config.py

99 lines
4.8 KiB
Python
Raw Normal View History

2015-07-24 18:05:51 +02:00
# coding: utf-8
2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 18:05:51 +02:00
do_autopath()
2019-12-24 15:24:20 +01:00
import pytest
2015-07-24 18:05:51 +02:00
from tiramisu.setting import groups
from tiramisu import Config, MetaConfig, ChoiceOption, BoolOption, IntOption, \
StrOption, OptionDescription, groups
from .test_state import _diff_opts, _diff_conf
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__)
2015-07-24 18:05:51 +02:00
def make_description():
numero_etab = StrOption('numero_etab', "identifiant de l'établissement")
nom_machine = StrOption('nom_machine', "nom de la machine", default="eoleng")
nombre_interfaces = IntOption('nombre_interfaces', "nombre d'interfaces à activer",
default=1)
activer_proxy_client = BoolOption('activer_proxy_client', "utiliser un proxy",
default=False)
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
default=False)
mode_conteneur_actif2 = BoolOption('mode_conteneur_actif2', "le serveur est en mode conteneur2",
default=False, properties=('hidden',))
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
('Paris', 'Londres'), 'Paris')
2016-09-22 08:27:18 +02:00
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',))
2015-07-24 18:05:51 +02:00
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
2019-02-23 19:06:23 +01:00
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [leader])
2015-07-24 18:05:51 +02:00
general = OptionDescription('general', '', [numero_etab, nom_machine,
nombre_interfaces, activer_proxy_client,
mode_conteneur_actif, mode_conteneur_actif2,
2016-09-22 08:27:18 +02:00
adresse_serveur_ntp, time_zone, wantref_option])
2015-07-24 18:05:51 +02:00
new = OptionDescription('new', '', [], properties=('hidden',))
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
return descr
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_copy():
cfg = await Config(make_description())
ncfg = await cfg.config.copy()
assert await cfg.option('creole.general.numero_etab').value.get() == None
await cfg.option('creole.general.numero_etab').value.set('oui')
assert await cfg.option('creole.general.numero_etab').value.get() == 'oui'
assert await ncfg.option('creole.general.numero_etab').value.get() == None
# _diff_opts(await cfg.cfgimpl_get_description(), nawait cfg.cfgimpl_get_description())
2018-03-19 08:33:53 +01:00
# _diff_conf(cfg, ncfg)
2019-12-24 15:24:20 +01:00
# await cfg.creole.general.numero_etab = 'oui'
2018-03-19 08:33:53 +01:00
# raises(AssertionError, "_diff_conf(cfg, ncfg)")
2019-12-24 15:24:20 +01:00
# nawait cfg.creole.general.numero_etab = 'oui'
2018-03-19 08:33:53 +01:00
# _diff_conf(cfg, ncfg)
2018-06-09 18:59:40 +02:00
def to_tuple(val):
return tuple([tuple(v) for v in val])
2016-09-22 08:27:18 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_copy_force_store_value():
2016-09-22 08:27:18 +02:00
descr = make_description()
2019-12-24 15:24:20 +01:00
conf = await Config(descr)
conf2 = await Config(descr)
assert to_tuple(await conf.value.exportation()) == ((), (), (), ())
assert to_tuple(await conf2.value.exportation()) == ((), (), (), ())
2019-02-21 19:33:39 +01:00
#
2019-12-24 15:24:20 +01:00
await conf.property.read_write()
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(await conf2.value.exportation()) == ((), (), (), ())
2019-02-21 19:33:39 +01:00
#
2019-12-24 15:24:20 +01:00
await conf2.property.read_only()
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(await conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
2019-02-21 19:33:39 +01:00
#
2019-12-24 15:24:20 +01:00
await conf.option('creole.general.wantref').value.set(True)
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',))
assert to_tuple(await conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_copy_force_store_value_metaconfig():
descr = make_description()
2019-12-24 15:24:20 +01:00
meta = await MetaConfig([], optiondescription=descr)
conf = await meta.config.new(session_id='conf')
assert await meta.property.get() == await conf.property.get()
assert await meta.permissive.get() == await conf.permissive.get()
await conf.property.read_write()
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(await meta.value.exportation()) == ((), (), (), ())