Debian Codegraph @

ansible_collections/dellemc/openmanage/tests/unit/plugins/modules/conftest.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 #
4 # Dell OpenManage Ansible Modules
5 # Version 7.0.0
6 # Copyright (C) 2019-2022 Dell Inc.
7
8 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # All rights reserved. Dell, EMC, and other trademarks are trademarks of Dell Inc. or its subsidiaries.
10 # Other trademarks may be trademarks of their respective owners.
11 #
12
13 from __future__ import (absolute_import, division, print_function)
14
15 __metaclass__ = type
16
17 import pytest
18 from ansible.module_utils import basic
19 from ansible_collections.dellemc.openmanage.tests.unit.plugins.modules.utils import exit_json, \
20 fail_json, AnsibleFailJson, AnsibleExitJson
21 from unittest.mock import MagicMock
22
23 MODULE_PATH = 'ansible_collections.dellemc.openmanage.plugins.modules.'
24 MODULE_UTIL_PATH = 'ansible_collections.dellemc.openmanage.plugins.module_utils.'
25
26
27 @pytest.fixture(autouse=True)
28 def module_mock(mocker):
29 return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
30
31
32 @pytest.fixture
33 def ome_connection_mock(mocker, ome_response_mock):
34 connection_class_mock = mocker.patch(MODULE_PATH + 'ome_device_info.RestOME')
35 ome_connection_mock_obj = connection_class_mock.return_value.__enter__.return_value
36 ome_connection_mock_obj.invoke_request.return_value = ome_response_mock
37 return ome_connection_mock_obj
38
39
40 @pytest.fixture
41 def ome_response_mock(mocker):
42 set_method_result = {'json_data': {}}
43 response_class_mock = mocker.patch(MODULE_UTIL_PATH + 'ome.OpenURLResponse', return_value=set_method_result)
44 response_class_mock.success = True
45 response_class_mock.status_code = 200
46 return response_class_mock
47
48
49 @pytest.fixture
50 def redfish_response_mock(mocker):
51 set_method_result = {'json_data': {}}
52 response_class_mock = mocker.patch(MODULE_UTIL_PATH + 'redfish.OpenURLResponse', return_value=set_method_result)
53 response_class_mock.success = True
54 response_class_mock.status_code = 200
55 return response_class_mock
56
57
58 @pytest.fixture
59 def ome_default_args():
60 default_args = {'hostname': 'XX.XX.XX.XX', 'username': 'username', 'password': 'password', "ca_path": "/path/ca_bundle"}
61 return default_args
62
63
64 @pytest.fixture
65 def omevv_default_args():
66 default_args = {'hostname': 'XX.XX.XX.XX', 'vcenter_uuid': 'vcenter_uuid', 'vcenter_username': 'vcenter_username',
67 'vcenter_password': 'vcenter_password', "ca_path": "/path/ca_bundle"}
68 return default_args
69
70
71 @pytest.fixture
72 def idrac_default_args():
73 default_args = {"idrac_ip": "idrac_ip", "idrac_user": "idrac_user", "idrac_password": "idrac_password",
74 "ca_path": "/path/to/ca_cert.pem"}
75 return default_args
76
77
78 @pytest.fixture
79 def redfish_default_args():
80 default_args = {'baseuri': 'XX.XX.XX.XX', 'username': 'username', 'password': 'password',
81 "ca_path": "/path/to/ca_cert.pem"}
82 return default_args
83
84
85 @pytest.fixture
86 def fake_ansible_module_mock():
87 module = MagicMock()
88 module.params = {}
89 module.fail_json = AnsibleFailJson()
90 module.exit_json = AnsibleExitJson()
91 return module
92
93
94 @pytest.fixture
95 def default_ome_args():
96 return {"hostname": "hostname", "username": "username", "password": "password"}