Debian Codegraph @

ansible_collections/splunk/es/tests/unit/plugins/modules/conftest.py

raw
1 # Copyright (c) 2017 Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 import json
5
6 import pytest
7
8 from ansible.module_utils.common._collections_compat import MutableMapping
9 from ansible.module_utils.common.text.converters import to_bytes
10
11
12 @pytest.fixture
13 def patch_ansible_module(request, mocker):
14 if isinstance(request.param, str):
15 args = request.param
16 elif isinstance(request.param, MutableMapping):
17 if "ANSIBLE_MODULE_ARGS" not in request.param:
18 request.param = {"ANSIBLE_MODULE_ARGS": request.param}
19 if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]:
20 request.param["ANSIBLE_MODULE_ARGS"]["_ansible_remote_tmp"] = "/tmp"
21 if "_ansible_keep_remote_files" not in request.param["ANSIBLE_MODULE_ARGS"]:
22 request.param["ANSIBLE_MODULE_ARGS"]["_ansible_keep_remote_files"] = False
23 args = json.dumps(request.param)
24 else:
25 raise Exception(
26 "Malformed data to the patch_ansible_module pytest fixture",
27 )
28
29 mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args))