From 87093da974c47e7d01bed704d462c3d8b3a5b06c Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 3 Apr 2021 20:38:08 +0200 Subject: [PATCH] add test about deepcopy with multi parents --- tests/test_dyn_optiondescription.py | 1 - tests/test_metaconfig.py | 33 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_dyn_optiondescription.py b/tests/test_dyn_optiondescription.py index 62373ca..431e7d0 100644 --- a/tests/test_dyn_optiondescription.py +++ b/tests/test_dyn_optiondescription.py @@ -268,7 +268,6 @@ async def test_prop_dyndescription_force_store_value(): @pytest.mark.asyncio async def test_prop_dyndescription_force_store_value_calculation_prefix(): - print() lst = StrOption('lst', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) diff --git a/tests/test_metaconfig.py b/tests/test_metaconfig.py index cf216f6..8d6b98e 100644 --- a/tests/test_metaconfig.py +++ b/tests/test_metaconfig.py @@ -1130,6 +1130,39 @@ async def test_meta_properties_meta_deepcopy(): await delete_sessions([meta, meta2]) +@pytest.mark.asyncio +async def test_meta_properties_meta_deepcopy_multi_parent(): + ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") + netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") + interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + conf1 = await Config(interface1, session_id='conf1') + conf2 = await Config(interface1, session_id='conf2') + await conf1.property.read_write() + await conf2.property.read_write() + meta1 = await MetaConfig([conf1, conf2], session_id='meta1') + await meta1.permissive.add('hidden') + await meta1.property.read_write() + + meta2 = await MetaConfig(['name1', 'name2'], optiondescription=interface1, session_id='meta2') + await meta2.config.add(conf1) + + await meta1.option('ip_admin_eth0').value.set('192.168.1.1') + await meta2.option('netmask_admin_eth0').value.set('255.255.255.0') + + assert await meta1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None} + assert await meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'} + assert await conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'} + assert await conf2.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None} + + copy_meta2 = await conf1.config.deepcopy(session_id='copy_conf1', metaconfig_prefix='copy_') + assert await copy_meta2.config.path() == 'copy_meta2' + copy_meta1 = await copy_meta2.config('copy_meta1') + copy_conf1 = await copy_meta1.config('copy_conf1') + assert await copy_meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'} + assert await copy_conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'} + await delete_sessions([conf1, conf2, meta1, meta2, copy_conf1, copy_meta1, copy_meta2]) + + @pytest.mark.asyncio async def test_meta_properties_submeta_deepcopy(): ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])