Debian Codegraph @

ansible_collections/community/aws/tests/unit/plugins/modules/conftest.py

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