From ef8930961184adfa30cb883051400bea4d016518 Mon Sep 17 00:00:00 2001 From: Fabio Bertagna <33524186+DonGiovanni83@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:00:37 +0100 Subject: [PATCH] Fix failing alias tests (#165) * Fix alias test imports * Fix XML multiline formating * Fix FirewallAlias counter type in tests * Format fw alias unit tests --- .../module_utils/test_firewall_alias_utils.py | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 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..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,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 @@ -240,11 +241,9 @@ 0 - - CF - DZ - AG - + CF +DZ +AG geoip_test @@ -447,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", @@ -459,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"{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)}" ) @@ -476,7 +474,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", @@ -488,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"{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)}" ) @@ -505,7 +502,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", @@ -517,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"{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)}" ) @@ -534,7 +530,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", @@ -548,8 +544,7 @@ 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)}" ) @@ -565,7 +560,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", @@ -579,8 +574,7 @@ 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)}" ) @@ -596,7 +590,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", @@ -610,8 +604,7 @@ 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)}" ) @@ -627,7 +620,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", @@ -641,8 +634,7 @@ 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 +1309,9 @@ 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 +1368,7 @@ 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)}" )