From a032a22c6975e4c524eb84e03c13ca5ae55ceb71 Mon Sep 17 00:00:00 2001 From: Fabio Bertagna Date: Thu, 19 Dec 2024 09:31:17 +0100 Subject: [PATCH 1/4] Fix alias test imports --- .../module_utils/test_firewall_alias_utils.py | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py index b3d4e5ba..bb5c2732 100644 --- a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py +++ b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py @@ -28,6 +28,7 @@ ) from ansible_collections.puzzle.opnsense.plugins.module_utils.xml_utils import ( elements_equal, + etree_to_dict ) # Test version map for OPNsense versions and modules @@ -459,8 +460,8 @@ def test_firewall_alias_to_etree(): orig_alias: Element = test_etree_opnsense.find("OPNsense/Firewall/Alias/aliases")[0] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -488,8 +489,8 @@ def test_firewall_alias_to_etree_with_content(): orig_alias: Element = test_etree_opnsense.find("OPNsense/Firewall/Alias/aliases")[5] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -517,8 +518,8 @@ def test_firewall_alias_to_etree_with_updatefreq(): orig_alias: Element = test_etree_opnsense.find("OPNsense/Firewall/Alias/aliases")[4] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -548,8 +549,8 @@ def test_firewall_alias_to_etree_with_bgpasn_none(): ] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -579,8 +580,8 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv4(): ] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -610,8 +611,8 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv6(): ] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -641,8 +642,8 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv4_ipv6(): ] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -1317,9 +1318,10 @@ def test_firewall_alias_from_ansible_module_params_with_content_type_bgpasn_vali 12 ] - assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + # description has changed + assert not elements_equal(test_element, orig_alias), ( + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) @@ -1376,8 +1378,8 @@ def test_firewall_alias_from_ansible_module_params_with_content_type_bgpasn_list ] assert elements_equal(test_element, orig_alias), ( - f"{xml_utils.etree_to_dict(test_element)}\n" - f"{xml_utils.etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" + f"{etree_to_dict(orig_alias)}" ) From ecac4ff77d517fe71545f42a4cab72d5d2beb6ea Mon Sep 17 00:00:00 2001 From: Fabio Bertagna Date: Thu, 19 Dec 2024 09:31:41 +0100 Subject: [PATCH 2/4] Fix XML multiline formating --- .../plugins/module_utils/test_firewall_alias_utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py index bb5c2732..553807ee 100644 --- a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py +++ b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py @@ -241,11 +241,9 @@ 0 - - CF - DZ - AG - + CF +DZ +AG geoip_test From 55c41f6afbc6c8d6c9235bbcd97b444c7d52095f Mon Sep 17 00:00:00 2001 From: Fabio Bertagna Date: Thu, 19 Dec 2024 09:31:59 +0100 Subject: [PATCH 3/4] Fix FirewallAlias counter type in tests --- .../module_utils/test_firewall_alias_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py index 553807ee..90e72c4b 100644 --- a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py +++ b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py @@ -446,7 +446,7 @@ def test_firewall_alias_to_etree(): type=FirewallAliasType.HOSTS.value, proto=None, interface=None, - counters="0", + counters=False, updatefreq=None, content="10.0.0.1", description="host_test", @@ -475,7 +475,7 @@ def test_firewall_alias_to_etree_with_content(): type=FirewallAliasType.GEOIP, proto=IPProtocol.IPv4, interface=None, - counters="0", + counters=False, updatefreq=None, content=["CF", "DZ", "AG"], description="geoip_test", @@ -504,7 +504,7 @@ def test_firewall_alias_to_etree_with_updatefreq(): type=FirewallAliasType.URLTABLES.value, proto=None, interface=None, - counters="0", + counters=False, updatefreq="2", content="www.puzzle.ch", description="url_table_test", @@ -533,7 +533,7 @@ def test_firewall_alias_to_etree_with_bgpasn_none(): type=FirewallAliasType.BGPASN.value, proto=None, interface=None, - counters="0", + counters=False, categories=None, content="123456", description="bgp_test_none", @@ -564,7 +564,7 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv4(): type=FirewallAliasType.BGPASN.value, proto="IPv4", interface=None, - counters="0", + counters=False, categories=None, content="123456", description="bgp_test_ipv4", @@ -595,7 +595,7 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv6(): type=FirewallAliasType.BGPASN.value, proto="IPv6", interface=None, - counters="0", + counters=False, categories=None, content="123456", description="bgp_test_ipv6", @@ -626,7 +626,7 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv4_ipv6(): type=FirewallAliasType.BGPASN.value, proto="IPv4,IPv6", interface=None, - counters="0", + counters=False, categories=None, content="123456", description="bgp_test_ipv4_ipv6", From 8bfc0cc1c4e154af7bf038ab4fe39fd9594434a5 Mon Sep 17 00:00:00 2001 From: Fabio Bertagna Date: Thu, 19 Dec 2024 09:39:12 +0100 Subject: [PATCH 4/4] Format fw alias unit tests --- .../module_utils/test_firewall_alias_utils.py | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py index 90e72c4b..1dff5141 100644 --- a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py +++ b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py @@ -28,7 +28,7 @@ ) from ansible_collections.puzzle.opnsense.plugins.module_utils.xml_utils import ( elements_equal, - etree_to_dict + etree_to_dict, ) # Test version map for OPNsense versions and modules @@ -458,8 +458,7 @@ def test_firewall_alias_to_etree(): orig_alias: Element = test_etree_opnsense.find("OPNsense/Firewall/Alias/aliases")[0] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -487,8 +486,7 @@ def test_firewall_alias_to_etree_with_content(): orig_alias: Element = test_etree_opnsense.find("OPNsense/Firewall/Alias/aliases")[5] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -516,8 +514,7 @@ def test_firewall_alias_to_etree_with_updatefreq(): orig_alias: Element = test_etree_opnsense.find("OPNsense/Firewall/Alias/aliases")[4] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -547,8 +544,7 @@ def test_firewall_alias_to_etree_with_bgpasn_none(): ] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -578,8 +574,7 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv4(): ] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -609,8 +604,7 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv6(): ] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -640,8 +634,7 @@ def test_firewall_alias_to_etree_with_bgpasn_ipv4_ipv6(): ] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -1318,8 +1311,7 @@ def test_firewall_alias_from_ansible_module_params_with_content_type_bgpasn_vali # description has changed assert not elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" ) @@ -1376,8 +1368,7 @@ def test_firewall_alias_from_ansible_module_params_with_content_type_bgpasn_list ] assert elements_equal(test_element, orig_alias), ( - f"{etree_to_dict(test_element)}\n" - f"{etree_to_dict(orig_alias)}" + f"{etree_to_dict(test_element)}\n" f"{etree_to_dict(orig_alias)}" )