From f437bb78f3ffb1ac9f322a8833b10c144dd274cd Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 21 Apr 2020 09:16:29 +0200 Subject: [PATCH] add a test with default_multi for a submulti follower --- tests/test_submulti.py | 46 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/test_submulti.py b/tests/test_submulti.py index 2479aaf..92d5a24 100644 --- a/tests/test_submulti.py +++ b/tests/test_submulti.py @@ -5,7 +5,6 @@ import pytest import warnings -from tiramisu.api import TIRAMISU_VERSION from tiramisu.setting import groups, owners from tiramisu import StrOption, IntOption, OptionDescription, submulti, Leadership, Config, \ MetaConfig, undefined, Params, ParamOption, Calculation @@ -38,11 +37,7 @@ async def test_unknown_multi(): @pytest.mark.asyncio async def test_submulti(): multi = StrOption('multi', '', multi=submulti) - if TIRAMISU_VERSION == 2: - default_multi = 'yes' - else: - default_multi = ['yes'] - multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) + multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) async with await Config(od) as cfg: @@ -66,11 +61,7 @@ async def test_submulti_default_multi_not_list(): @pytest.mark.asyncio async def test_append_submulti(): multi = StrOption('multi', '', multi=submulti) - if TIRAMISU_VERSION == 2: - default_multi = 'yes' - else: - default_multi = ['yes'] - multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) + multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) async with await Config(od) as cfg: @@ -104,11 +95,7 @@ async def test_append_submulti(): @pytest.mark.asyncio async def test_append_unvalide_submulti(): multi = StrOption('multi', '', multi=submulti) - if TIRAMISU_VERSION == 2: - default_multi = 'yes' - else: - default_multi = ['yes'] - multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) + multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) async with await Config(od) as cfg: @@ -137,11 +124,7 @@ async def test_append_unvalide_submulti(): @pytest.mark.asyncio async def test_pop_submulti(): multi = StrOption('multi', '', multi=submulti) - if TIRAMISU_VERSION == 2: - default_multi = 'yes' - else: - default_multi = ['yes'] - multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti) + multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) od = OptionDescription('od', '', [multi, multi2, multi3]) async with await Config(od) as cfg: @@ -267,6 +250,27 @@ async def test_values_with_leader_and_followers_submulti(): assert not await list_sessions() +@pytest.mark.asyncio +async def test_values_with_leader_and_followers_submulti_default_multi(): + 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=submulti, default_multi=['255.255.0.0', '0.0.0.0']) + interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + maconfig = OptionDescription('toto', '', [interface1]) + async with await Config(maconfig) as cfg: + await cfg.property.read_write() + owner = await cfg.owner.get() + assert interface1.impl_get_group_type() == groups.leadership + assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default + await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) + assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"] + assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.0.0', '0.0.0.0'] + await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"]) + await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0']) + assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0'] + assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == ['255.255.0.0', '0.0.0.0'] + assert not await list_sessions() + + @pytest.mark.asyncio async def test_reset_values_with_leader_and_followers_submulti(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)