Debian Codegraph @

test/units/module_utils/common/parameters/test_check_arguments.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2020 Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7
8 import pytest
9
10 from ansible.module_utils.common.parameters import (
11 _get_unsupported_parameters,
12 _validate_argument_values,
13 )
14 from ansible.module_utils.errors import AnsibleValidationErrorMultiple
15
16
17 @pytest.fixture
18 def argument_spec():
19 return {
20 'state': {'aliases': ['status']},
21 'enabled': {},
22 }
23
24
25 @pytest.mark.parametrize(
26 ('module_parameters', 'legal_inputs', 'expected'),
27 (
28 ({'fish': 'food'}, ['state', 'enabled'], set(['fish'])),
29 ({'state': 'enabled', 'path': '/var/lib/path'}, None, set(['path'])),
30 ({'state': 'enabled', 'path': '/var/lib/path'}, ['state', 'path'], set()),
31 ({'state': 'enabled', 'path': '/var/lib/path'}, ['state'], set(['path'])),
32 ({}, None, set()),
33 ({'state': 'enabled'}, None, set()),
34 ({'status': 'enabled', 'enabled': True, 'path': '/var/lib/path'}, None, set(['path'])),
35 ({'status': 'enabled', 'enabled': True}, None, set()),
36 )
37 )
38 def test_check_arguments(argument_spec, module_parameters, legal_inputs, expected, mocker):
39 result = _get_unsupported_parameters(argument_spec, module_parameters, legal_inputs)
40
41 assert result == expected
42
43
44 def test_validate_argument_values(mocker):
45 argument_spec = {
46 "foo": {"type": "list", "elements": "int", "choices": [1]},
47 }
48 module_parameters = {"foo": [2]}
49 errors = AnsibleValidationErrorMultiple()
50 result = _validate_argument_values(argument_spec, module_parameters, errors=errors)
51 assert "value of foo must be one" in errors[0].msg