File: test_debconf.py

package info (click to toggle)
ansible-core 2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 32,752 kB
  • sloc: python: 181,000; cs: 4,929; sh: 4,611; xml: 34; makefile: 21
file content (63 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations

import pytest

from ansible.modules.debconf import get_password_value


password_testdata = [
    pytest.param(
        (
            "ddclient2	ddclient/password1	password	Sample",
            "ddclient2",
            "ddclient/password1",
            "password",
        ),
        "Sample",
        id="valid_password",
    ),
    pytest.param(
        (
            "ddclient2	ddclient/password1	password",
            "ddclient2",
            "ddclient/password1",
            "password",
        ),
        '',
        id="invalid_password",
    ),
    pytest.param(
        (
            "ddclient2	ddclient/password	password",
            "ddclient2",
            "ddclient/password1",
            "password",
        ),
        '',
        id="invalid_password_none",
    ),
    pytest.param(
        (
            "ddclient2	ddclient/password",
            "ddclient2",
            "ddclient/password",
            "password",
        ),
        '',
        id="invalid_line",
    ),
]


@pytest.mark.parametrize("test_input,expected", password_testdata)
def test_get_password_value(mocker, test_input, expected):
    module = mocker.MagicMock()
    mocker.patch.object(
        module, "get_bin_path", return_value="/usr/bin/debconf-get-selections"
    )
    mocker.patch.object(module, "run_command", return_value=(0, test_input[0], ""))

    res = get_password_value(module, *test_input[1:])
    assert res == expected