Debian Codegraph @

test/units/modules/test_debconf.py

raw
1 # Copyright: Contributors to the Ansible project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3 from __future__ import annotations
4
5 import pytest
6
7 from ansible.modules.debconf import get_password_value
8
9
10 password_testdata = [
11 pytest.param(
12 (
13 "ddclient2 ddclient/password1 password Sample",
14 "ddclient2",
15 "ddclient/password1",
16 "password",
17 ),
18 "Sample",
19 id="valid_password",
20 ),
21 pytest.param(
22 (
23 "ddclient2 ddclient/password1 password",
24 "ddclient2",
25 "ddclient/password1",
26 "password",
27 ),
28 '',
29 id="invalid_password",
30 ),
31 pytest.param(
32 (
33 "ddclient2 ddclient/password password",
34 "ddclient2",
35 "ddclient/password1",
36 "password",
37 ),
38 '',
39 id="invalid_password_none",
40 ),
41 pytest.param(
42 (
43 "ddclient2 ddclient/password",
44 "ddclient2",
45 "ddclient/password",
46 "password",
47 ),
48 '',
49 id="invalid_line",
50 ),
51 ]
52
53
54 @pytest.mark.parametrize("test_input,expected", password_testdata)
55 def test_get_password_value(mocker, test_input, expected):
56 module = mocker.MagicMock()
57 mocker.patch.object(
58 module, "get_bin_path", return_value="/usr/bin/debconf-get-selections"
59 )
60 mocker.patch.object(module, "run_command", return_value=(0, test_input[0], ""))
61
62 res = get_password_value(module, *test_input[1:])
63 assert res == expected