File: test_utils.py

package info (click to toggle)
python-consul 1.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 480 kB
  • sloc: python: 2,842; makefile: 197
file content (71 lines) | stat: -rw-r--r-- 2,182 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
from tests.utils import find_recursive, should_skip


def test_find_recursive() -> None:
    ret_value = [
        {
            "AccessorID": "accessorid",
            "CreateIndex": 1,
            "CreateTime": "timestamp",
            "Description": "description",
            "Hash": "hash",
            "Local": False,
            "ModifyIndex": 1,
            "Policies": [{"ID": "id", "Name": "name"}],
            "SecretID": "secretid",
        },
        {
            "AccessorID": "accessorid",
            "CreateIndex": 1,
            "CreateTime": "timestamp",
            "Description": "description",
            "Hash": "hash",
            "Local": False,
            "ModifyIndex": 1,
            "Policies": [{"ID": "id", "Name": "name"}],
            "SecretID": "secretid2",
        },
    ]

    wanted = {
        "AccessorID": "accessorid",
        "Description": "description",
        "Policies": [{"Name": "name"}],
        "SecretID": "secretid",
    }
    wanted2 = {
        "AccessorID": "accessorid",
        "SecretID": "secretid2",
    }
    unwanted = {
        "AccessorID": "accessorid",
        "Description": "description",
        "Policies": [{"Name": "name-ish"}],
        "SecretID": "secretid",
    }

    assert find_recursive(ret_value, wanted)
    assert find_recursive(ret_value, wanted2)
    assert find_recursive(ret_value, [wanted, wanted2])
    assert find_recursive(wanted, wanted)
    assert not find_recursive(ret_value, unwanted)


def test_should_skip() -> None:
    test_cases = [
        ("1.0.0", "<=", "1.0.0", False),
        ("1.0.1", "<=", "1.0.0", True),
        ("0.9.9", "<=", "1.0.0", False),
        ("1.0.0", ">=", "1.0.0", False),
        ("1.0.1", ">=", "1.0.0", False),
        ("0.9.9", ">=", "1.0.0", True),
        ("1.0.0", "<", "1.0.0", True),
        ("1.0.1", "<", "1.0.0", True),
        ("0.9.9", "<", "1.0.0", False),
        ("1.0.0", ">", "1.0.0", True),
        ("1.0.1", ">", "1.0.0", False),
        ("0.9.9", ">", "1.0.0", True),
    ]

    for version_str, comparator, ref_version_str, expected in test_cases:
        assert should_skip(version_str, comparator, ref_version_str) == expected