Skip to content

Commit

Permalink
Fix failing alias tests (puzzle#165)
Browse files Browse the repository at this point in the history
* Fix alias test imports

* Fix XML multiline formating

* Fix FirewallAlias counter type in tests

* Format fw alias unit tests
  • Loading branch information
DonGiovanni83 authored Dec 19, 2024
1 parent 2705319 commit ef89309
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions tests/unit/plugins/module_utils/test_firewall_alias_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -240,11 +241,9 @@
<interface/>
<counters>0</counters>
<updatefreq/>
<content>
CF
DZ
AG
</content>
<content>CF
DZ
AG</content>
<description>geoip_test</description>
</alias>
<alias uuid="7e776c20-5658-45fb-924d-9fd833eae142">
Expand Down Expand Up @@ -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",
Expand All @@ -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)}"
)


Expand All @@ -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",
Expand All @@ -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)}"
)


Expand All @@ -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",
Expand All @@ -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)}"
)


Expand All @@ -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",
Expand All @@ -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)}"
)


Expand All @@ -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",
Expand All @@ -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)}"
)


Expand All @@ -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",
Expand All @@ -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)}"
)


Expand All @@ -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",
Expand All @@ -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)}"
)


Expand Down Expand Up @@ -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)}"
)


Expand Down Expand Up @@ -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)}"
)


Expand Down

0 comments on commit ef89309

Please sign in to comment.