mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Stop re-defining the argument spec in unit tests (#11235)
* Stop re-defining the argument spec in unit tests. * Shut up linter.
This commit is contained in:
parent
6365b5a981
commit
fb2f34ba85
6 changed files with 35 additions and 274 deletions
|
|
@ -589,7 +589,7 @@ def get_archive(module):
|
|||
return TarArchive(module)
|
||||
|
||||
|
||||
def main():
|
||||
def create_module() -> AnsibleModule:
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
path=dict(type="list", elements="path", required=True),
|
||||
|
|
@ -603,6 +603,11 @@ def main():
|
|||
add_file_common_args=True,
|
||||
supports_check_mode=True,
|
||||
)
|
||||
return module
|
||||
|
||||
|
||||
def main():
|
||||
module = create_module()
|
||||
|
||||
check_mode = module.check_mode
|
||||
|
||||
|
|
|
|||
|
|
@ -510,7 +510,7 @@ def create_file(content):
|
|||
return tmpfile
|
||||
|
||||
|
||||
def main():
|
||||
def create_module() -> AnsibleModule:
|
||||
choose_between = (["certificate", "certificate_path"], ["private_key", "private_key_path"])
|
||||
|
||||
module = AnsibleModule(
|
||||
|
|
@ -533,6 +533,11 @@ def main():
|
|||
add_file_common_args=True,
|
||||
)
|
||||
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C")
|
||||
return module
|
||||
|
||||
|
||||
def main():
|
||||
module = create_module()
|
||||
|
||||
result = dict()
|
||||
jks = JavaKeystore(module)
|
||||
|
|
|
|||
|
|
@ -2675,8 +2675,7 @@ class Nmcli:
|
|||
return self._compare_conn_params(self.show_connection(), options)
|
||||
|
||||
|
||||
def main():
|
||||
# Parsing argument file
|
||||
def create_module() -> AnsibleModule:
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
ignore_unsupported_suboptions=dict(type="bool", default=False),
|
||||
|
|
@ -2870,6 +2869,12 @@ def main():
|
|||
supports_check_mode=True,
|
||||
)
|
||||
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
|
||||
return module
|
||||
|
||||
|
||||
def main():
|
||||
# Parsing argument file
|
||||
module = create_module()
|
||||
|
||||
nmcli = Nmcli(module)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,11 @@ from __future__ import annotations
|
|||
import pytest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
from ansible_collections.community.general.plugins.modules.archive import get_archive, common_path
|
||||
from ansible_collections.community.general.plugins.modules.archive import get_archive, common_path, create_module
|
||||
|
||||
|
||||
class TestArchive(ModuleTestCase):
|
||||
|
|
@ -27,19 +26,7 @@ class TestArchive(ModuleTestCase):
|
|||
|
||||
def test_archive_removal_safety(self):
|
||||
with set_module_args(dict(path=["/foo", "/bar", "/baz"], dest="/foo/destination.tgz", remove=True)):
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
path=dict(type="list", elements="path", required=True),
|
||||
format=dict(type="str", default="gz", choices=["bz2", "gz", "tar", "xz", "zip"]),
|
||||
dest=dict(type="path"),
|
||||
exclude_path=dict(type="list", elements="path", default=[]),
|
||||
exclusion_patterns=dict(type="list", elements="path"),
|
||||
force_archive=dict(type="bool", default=False),
|
||||
remove=dict(type="bool", default=False),
|
||||
),
|
||||
add_file_common_args=True,
|
||||
supports_check_mode=True,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
self.os_path_isdir.side_effect = [True, False, False, True]
|
||||
|
||||
|
|
|
|||
|
|
@ -13,25 +13,8 @@ from ansible_collections.community.internal_test_tools.tests.unit.plugins.module
|
|||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.modules.java_keystore import JavaKeystore
|
||||
|
||||
|
||||
module_argument_spec = dict(
|
||||
name=dict(type="str", required=True),
|
||||
dest=dict(type="path", required=True),
|
||||
certificate=dict(type="str", no_log=True),
|
||||
certificate_path=dict(type="path"),
|
||||
private_key=dict(type="str", no_log=True),
|
||||
private_key_path=dict(type="path", no_log=False),
|
||||
private_key_passphrase=dict(type="str", no_log=True),
|
||||
password=dict(type="str", required=True, no_log=True),
|
||||
ssl_backend=dict(type="str", default="openssl", choices=["openssl", "cryptography"]),
|
||||
keystore_type=dict(type="str", choices=["jks", "pkcs12"]),
|
||||
force=dict(type="bool", default=False),
|
||||
)
|
||||
module_supports_check_mode = True
|
||||
module_choose_between = (["certificate", "certificate_path"], ["private_key", "private_key_path"])
|
||||
from ansible.module_utils.basic import AnsibleModule # noqa: F401 # pylint: disable=unused-import
|
||||
from ansible_collections.community.general.plugins.modules.java_keystore import JavaKeystore, create_module
|
||||
|
||||
|
||||
class TestCreateJavaKeystore(ModuleTestCase):
|
||||
|
|
@ -96,12 +79,7 @@ class TestCreateJavaKeystore(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
with patch("os.remove", return_value=True):
|
||||
self.create_path.side_effect = ["/tmp/tmpgrzm2ah7"]
|
||||
|
|
@ -139,12 +117,7 @@ class TestCreateJavaKeystore(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
module.exit_json = Mock()
|
||||
module.fail_json = Mock()
|
||||
|
|
@ -189,12 +162,7 @@ class TestCreateJavaKeystore(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
module.exit_json = Mock()
|
||||
module.fail_json = Mock()
|
||||
|
|
@ -237,12 +205,7 @@ class TestCreateJavaKeystore(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
module.exit_json = Mock()
|
||||
module.fail_json = Mock()
|
||||
|
|
@ -315,12 +278,7 @@ class TestCertChanged(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
with patch("os.remove", return_value=True):
|
||||
self.create_file.side_effect = ["/tmp/placeholder", ""]
|
||||
|
|
@ -341,12 +299,7 @@ class TestCertChanged(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
with patch("os.remove", return_value=True):
|
||||
self.create_file.side_effect = ["/tmp/placeholder", ""]
|
||||
|
|
@ -367,12 +320,7 @@ class TestCertChanged(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
with patch("os.remove", return_value=True):
|
||||
self.create_file.side_effect = ["/tmp/placeholder", ""]
|
||||
|
|
@ -395,12 +343,7 @@ class TestCertChanged(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
with patch("os.remove", return_value=True):
|
||||
self.create_file.side_effect = ["/tmp/placeholder", ""]
|
||||
|
|
@ -423,12 +366,7 @@ class TestCertChanged(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
module.exit_json = Mock()
|
||||
module.fail_json = Mock()
|
||||
|
|
@ -457,12 +395,7 @@ class TestCertChanged(ModuleTestCase):
|
|||
password="changeit",
|
||||
)
|
||||
):
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_argument_spec,
|
||||
supports_check_mode=module_supports_check_mode,
|
||||
mutually_exclusive=module_choose_between,
|
||||
required_one_of=module_choose_between,
|
||||
)
|
||||
module = create_module()
|
||||
|
||||
module.exit_json = Mock()
|
||||
module.fail_json = Mock(return_value=True)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import pytest
|
|||
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible_collections.community.general.plugins.modules import nmcli
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule # noqa: F401 # pylint: disable=unused-import
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("patch_ansible_module")
|
||||
|
||||
|
|
@ -4576,181 +4576,7 @@ def test_bond_connection_unchanged_2(mocked_generic_connection_diff_check, capfd
|
|||
Test : Bond connection unchanged
|
||||
"""
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
ignore_unsupported_suboptions=dict(type="bool", default=False),
|
||||
autoconnect=dict(type="bool", default=True),
|
||||
autoconnect_priority=dict(type="int"),
|
||||
autoconnect_retries=dict(type="int"),
|
||||
state=dict(type="str", required=True, choices=["absent", "present"]),
|
||||
conn_name=dict(type="str", required=True),
|
||||
conn_reload=dict(type="bool", required=False, default=False),
|
||||
master=dict(type="str"),
|
||||
slave_type=dict(type=str, choices=["bond", "bridge", "team"]),
|
||||
ifname=dict(type="str"),
|
||||
type=dict(
|
||||
type="str",
|
||||
choices=[
|
||||
"bond",
|
||||
"bond-slave",
|
||||
"bridge",
|
||||
"bridge-slave",
|
||||
"dummy",
|
||||
"ethernet",
|
||||
"generic",
|
||||
"gre",
|
||||
"infiniband",
|
||||
"ipip",
|
||||
"sit",
|
||||
"team",
|
||||
"team-slave",
|
||||
"vlan",
|
||||
"vxlan",
|
||||
"wifi",
|
||||
"gsm",
|
||||
"macvlan",
|
||||
"wireguard",
|
||||
"vpn",
|
||||
],
|
||||
),
|
||||
ip4=dict(type="list", elements="str"),
|
||||
gw4=dict(type="str"),
|
||||
gw4_ignore_auto=dict(type="bool", default=False),
|
||||
routes4=dict(type="list", elements="str"),
|
||||
routes4_extended=dict(
|
||||
type="list",
|
||||
elements="dict",
|
||||
options=dict(
|
||||
ip=dict(type="str", required=True),
|
||||
next_hop=dict(type="str"),
|
||||
metric=dict(type="int"),
|
||||
table=dict(type="int"),
|
||||
tos=dict(type="int"),
|
||||
cwnd=dict(type="int"),
|
||||
mtu=dict(type="int"),
|
||||
onlink=dict(type="bool"),
|
||||
),
|
||||
),
|
||||
route_metric4=dict(type="int"),
|
||||
routing_rules4=dict(type="list", elements="str"),
|
||||
never_default4=dict(type="bool", default=False),
|
||||
dns4=dict(type="list", elements="str"),
|
||||
dns4_search=dict(type="list", elements="str"),
|
||||
dns4_options=dict(type="list", elements="str"),
|
||||
dns4_ignore_auto=dict(type="bool", default=False),
|
||||
method4=dict(type="str", choices=["auto", "link-local", "manual", "shared", "disabled"]),
|
||||
may_fail4=dict(type="bool", default=True),
|
||||
dhcp_client_id=dict(type="str"),
|
||||
ip6=dict(type="list", elements="str"),
|
||||
gw6=dict(type="str"),
|
||||
gw6_ignore_auto=dict(type="bool", default=False),
|
||||
dns6=dict(type="list", elements="str"),
|
||||
dns6_search=dict(type="list", elements="str"),
|
||||
dns6_options=dict(type="list", elements="str"),
|
||||
dns6_ignore_auto=dict(type="bool", default=False),
|
||||
routes6=dict(type="list", elements="str"),
|
||||
routes6_extended=dict(
|
||||
type="list",
|
||||
elements="dict",
|
||||
options=dict(
|
||||
ip=dict(type="str", required=True),
|
||||
next_hop=dict(type="str"),
|
||||
metric=dict(type="int"),
|
||||
table=dict(type="int"),
|
||||
cwnd=dict(type="int"),
|
||||
mtu=dict(type="int"),
|
||||
onlink=dict(type="bool"),
|
||||
),
|
||||
),
|
||||
route_metric6=dict(type="int"),
|
||||
method6=dict(type="str", choices=["ignore", "auto", "dhcp", "link-local", "manual", "shared", "disabled"]),
|
||||
ip_privacy6=dict(type="str", choices=["disabled", "prefer-public-addr", "prefer-temp-addr", "unknown"]),
|
||||
addr_gen_mode6=dict(type="str", choices=["default", "default-or-eui64", "eui64", "stable-privacy"]),
|
||||
# Bond Specific vars
|
||||
mode=dict(
|
||||
type="str",
|
||||
default="balance-rr",
|
||||
choices=[
|
||||
"802.3ad",
|
||||
"active-backup",
|
||||
"balance-alb",
|
||||
"balance-rr",
|
||||
"balance-tlb",
|
||||
"balance-xor",
|
||||
"broadcast",
|
||||
],
|
||||
),
|
||||
miimon=dict(type="int"),
|
||||
downdelay=dict(type="int"),
|
||||
updelay=dict(type="int"),
|
||||
xmit_hash_policy=dict(type="str"),
|
||||
fail_over_mac=dict(type="str", choices=["none", "active", "follow"]),
|
||||
arp_interval=dict(type="int"),
|
||||
arp_ip_target=dict(type="str"),
|
||||
primary=dict(type="str"),
|
||||
# general usage
|
||||
mtu=dict(type="int"),
|
||||
mac=dict(type="str"),
|
||||
zone=dict(type="str"),
|
||||
# bridge specific vars
|
||||
stp=dict(type="bool", default=True),
|
||||
priority=dict(type="int", default=128),
|
||||
slavepriority=dict(type="int", default=32),
|
||||
forwarddelay=dict(type="int", default=15),
|
||||
hellotime=dict(type="int", default=2),
|
||||
maxage=dict(type="int", default=20),
|
||||
ageingtime=dict(type="int", default=300),
|
||||
hairpin=dict(type="bool"),
|
||||
path_cost=dict(type="int", default=100),
|
||||
# team specific vars
|
||||
runner=dict(
|
||||
type="str",
|
||||
default="roundrobin",
|
||||
choices=["broadcast", "roundrobin", "activebackup", "loadbalance", "lacp"],
|
||||
),
|
||||
# team active-backup runner specific options
|
||||
runner_hwaddr_policy=dict(type="str", choices=["same_all", "by_active", "only_active"]),
|
||||
# team lacp runner specific options
|
||||
runner_fast_rate=dict(type="bool"),
|
||||
# vlan specific vars
|
||||
vlanid=dict(type="int"),
|
||||
vlandev=dict(type="str"),
|
||||
flags=dict(type="str"),
|
||||
ingress=dict(type="str"),
|
||||
egress=dict(type="str"),
|
||||
# vxlan specific vars
|
||||
vxlan_id=dict(type="int"),
|
||||
vxlan_local=dict(type="str"),
|
||||
vxlan_remote=dict(type="str"),
|
||||
# ip-tunnel specific vars
|
||||
ip_tunnel_dev=dict(type="str"),
|
||||
ip_tunnel_local=dict(type="str"),
|
||||
ip_tunnel_remote=dict(type="str"),
|
||||
# ip-tunnel type gre specific vars
|
||||
ip_tunnel_input_key=dict(type="str", no_log=True),
|
||||
ip_tunnel_output_key=dict(type="str", no_log=True),
|
||||
# 802-11-wireless* specific vars
|
||||
ssid=dict(type="str"),
|
||||
wifi=dict(type="dict"),
|
||||
wifi_sec=dict(type="dict", no_log=True),
|
||||
gsm=dict(type="dict"),
|
||||
macvlan=dict(type="dict"),
|
||||
wireguard=dict(type="dict"),
|
||||
vpn=dict(type="dict"),
|
||||
sriov=dict(type="dict"),
|
||||
# infiniband specific vars
|
||||
transport_mode=dict(type="str", choices=["datagram", "connected"]),
|
||||
infiniband_mac=dict(type="str"),
|
||||
),
|
||||
mutually_exclusive=[
|
||||
["never_default4", "gw4"],
|
||||
["routes4_extended", "routes4"],
|
||||
["routes6_extended", "routes6"],
|
||||
],
|
||||
required_if=[("type", "wifi", [("ssid")])],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
|
||||
module = nmcli.create_module()
|
||||
|
||||
nmcli_module = nmcli.Nmcli(module)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue