mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Reformat everything.
This commit is contained in:
@@ -11,35 +11,41 @@ import pytest
|
||||
from ansible_collections.community.general.plugins.modules import lxca_cmms
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
@mock.patch('ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.close_conn', autospec=True)
|
||||
@pytest.fixture(scope="module")
|
||||
@mock.patch(
|
||||
"ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.close_conn", autospec=True
|
||||
)
|
||||
def setup_module(close_conn):
|
||||
close_conn.return_value = True
|
||||
|
||||
|
||||
class TestMyModule():
|
||||
@pytest.mark.parametrize('patch_ansible_module',
|
||||
[
|
||||
{},
|
||||
{
|
||||
"auth_url": "https://10.240.14.195",
|
||||
"login_user": "USERID",
|
||||
},
|
||||
{
|
||||
"auth_url": "https://10.240.14.195",
|
||||
"login_password": "Password",
|
||||
},
|
||||
{
|
||||
"login_user": "USERID",
|
||||
"login_password": "Password",
|
||||
},
|
||||
],
|
||||
indirect=['patch_ansible_module'])
|
||||
@pytest.mark.usefixtures('patch_ansible_module')
|
||||
@mock.patch('ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.setup_conn', autospec=True)
|
||||
@mock.patch('ansible_collections.community.general.plugins.modules.lxca_cmms.execute_module', autospec=True)
|
||||
def test_without_required_parameters(self, _setup_conn, _execute_module,
|
||||
mocker, capfd, setup_module):
|
||||
class TestMyModule:
|
||||
@pytest.mark.parametrize(
|
||||
"patch_ansible_module",
|
||||
[
|
||||
{},
|
||||
{
|
||||
"auth_url": "https://10.240.14.195",
|
||||
"login_user": "USERID",
|
||||
},
|
||||
{
|
||||
"auth_url": "https://10.240.14.195",
|
||||
"login_password": "Password",
|
||||
},
|
||||
{
|
||||
"login_user": "USERID",
|
||||
"login_password": "Password",
|
||||
},
|
||||
],
|
||||
indirect=["patch_ansible_module"],
|
||||
)
|
||||
@pytest.mark.usefixtures("patch_ansible_module")
|
||||
@mock.patch(
|
||||
"ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.setup_conn",
|
||||
autospec=True,
|
||||
)
|
||||
@mock.patch("ansible_collections.community.general.plugins.modules.lxca_cmms.execute_module", autospec=True)
|
||||
def test_without_required_parameters(self, _setup_conn, _execute_module, mocker, capfd, setup_module):
|
||||
"""Failure must occurs when all parameters are missing"""
|
||||
with pytest.raises(SystemExit):
|
||||
_setup_conn.return_value = "Fake connection"
|
||||
@@ -47,18 +53,20 @@ class TestMyModule():
|
||||
lxca_cmms.main()
|
||||
out, err = capfd.readouterr()
|
||||
results = json.loads(out)
|
||||
assert results['failed']
|
||||
assert 'missing required arguments' in results['msg']
|
||||
assert results["failed"]
|
||||
assert "missing required arguments" in results["msg"]
|
||||
|
||||
@mock.patch('ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.setup_conn', autospec=True)
|
||||
@mock.patch('ansible_collections.community.general.plugins.modules.lxca_cmms.execute_module', autospec=True)
|
||||
@mock.patch('ansible_collections.community.general.plugins.modules.lxca_cmms.AnsibleModule', autospec=True)
|
||||
@mock.patch(
|
||||
"ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.setup_conn",
|
||||
autospec=True,
|
||||
)
|
||||
@mock.patch("ansible_collections.community.general.plugins.modules.lxca_cmms.execute_module", autospec=True)
|
||||
@mock.patch("ansible_collections.community.general.plugins.modules.lxca_cmms.AnsibleModule", autospec=True)
|
||||
def test__argument_spec(self, ansible_mod_cls, _execute_module, _setup_conn, setup_module):
|
||||
expected_arguments_spec = dict(
|
||||
login_user=dict(required=True),
|
||||
login_password=dict(required=True, no_log=True),
|
||||
command_options=dict(default='cmms', choices=['cmms', 'cmms_by_uuid',
|
||||
'cmms_by_chassis_uuid']),
|
||||
command_options=dict(default="cmms", choices=["cmms", "cmms_by_uuid", "cmms_by_chassis_uuid"]),
|
||||
auth_url=dict(required=True),
|
||||
uuid=dict(),
|
||||
chassis=dict(),
|
||||
@@ -74,14 +82,14 @@ class TestMyModule():
|
||||
}
|
||||
mod_obj.params = args
|
||||
lxca_cmms.main()
|
||||
assert mock.call(argument_spec=expected_arguments_spec,
|
||||
supports_check_mode=False) == ansible_mod_cls.call_args
|
||||
assert mock.call(argument_spec=expected_arguments_spec, supports_check_mode=False) == ansible_mod_cls.call_args
|
||||
|
||||
@mock.patch('ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.setup_conn', autospec=True)
|
||||
@mock.patch('ansible_collections.community.general.plugins.modules.lxca_cmms._cmms_by_uuid',
|
||||
autospec=True)
|
||||
@mock.patch('ansible_collections.community.general.plugins.modules.lxca_cmms.AnsibleModule',
|
||||
autospec=True)
|
||||
@mock.patch(
|
||||
"ansible_collections.community.general.plugins.module_utils.remote_management.lxca.common.setup_conn",
|
||||
autospec=True,
|
||||
)
|
||||
@mock.patch("ansible_collections.community.general.plugins.modules.lxca_cmms._cmms_by_uuid", autospec=True)
|
||||
@mock.patch("ansible_collections.community.general.plugins.modules.lxca_cmms.AnsibleModule", autospec=True)
|
||||
def test__cmms_empty_list(self, ansible_mod_cls, _get_cmms, _setup_conn, setup_module):
|
||||
mod_obj = ansible_mod_cls.return_value
|
||||
args = {
|
||||
|
||||
Reference in New Issue
Block a user