| 1 | from tests.utils import find_recursive, should_skip |
| 2 | |
| 3 | |
| 4 | def test_find_recursive() -> None: |
| 5 | ret_value = [ |
| 6 | { |
| 7 | "AccessorID": "accessorid", |
| 8 | "CreateIndex": 1, |
| 9 | "CreateTime": "timestamp", |
| 10 | "Description": "description", |
| 11 | "Hash": "hash", |
| 12 | "Local": False, |
| 13 | "ModifyIndex": 1, |
| 14 | "Policies": [{"ID": "id", "Name": "name"}], |
| 15 | "SecretID": "secretid", |
| 16 | }, |
| 17 | { |
| 18 | "AccessorID": "accessorid", |
| 19 | "CreateIndex": 1, |
| 20 | "CreateTime": "timestamp", |
| 21 | "Description": "description", |
| 22 | "Hash": "hash", |
| 23 | "Local": False, |
| 24 | "ModifyIndex": 1, |
| 25 | "Policies": [{"ID": "id", "Name": "name"}], |
| 26 | "SecretID": "secretid2", |
| 27 | }, |
| 28 | ] |
| 29 | |
| 30 | wanted = { |
| 31 | "AccessorID": "accessorid", |
| 32 | "Description": "description", |
| 33 | "Policies": [{"Name": "name"}], |
| 34 | "SecretID": "secretid", |
| 35 | } |
| 36 | wanted2 = { |
| 37 | "AccessorID": "accessorid", |
| 38 | "SecretID": "secretid2", |
| 39 | } |
| 40 | unwanted = { |
| 41 | "AccessorID": "accessorid", |
| 42 | "Description": "description", |
| 43 | "Policies": [{"Name": "name-ish"}], |
| 44 | "SecretID": "secretid", |
| 45 | } |
| 46 | |
| 47 | assert find_recursive(ret_value, wanted) |
| 48 | assert find_recursive(ret_value, wanted2) |
| 49 | assert find_recursive(ret_value, [wanted, wanted2]) |
| 50 | assert find_recursive(wanted, wanted) |
| 51 | assert not find_recursive(ret_value, unwanted) |
| 52 | |
| 53 | |
| 54 | def test_should_skip() -> None: |
| 55 | test_cases = [ |
| 56 | ("1.0.0", "<=", "1.0.0", False), |
| 57 | ("1.0.1", "<=", "1.0.0", True), |
| 58 | ("0.9.9", "<=", "1.0.0", False), |
| 59 | ("1.0.0", ">=", "1.0.0", False), |
| 60 | ("1.0.1", ">=", "1.0.0", False), |
| 61 | ("0.9.9", ">=", "1.0.0", True), |
| 62 | ("1.0.0", "<", "1.0.0", True), |
| 63 | ("1.0.1", "<", "1.0.0", True), |
| 64 | ("0.9.9", "<", "1.0.0", False), |
| 65 | ("1.0.0", ">", "1.0.0", True), |
| 66 | ("1.0.1", ">", "1.0.0", False), |
| 67 | ("0.9.9", ">", "1.0.0", True), |
| 68 | ] |
| 69 | |
| 70 | for version_str, comparator, ref_version_str, expected in test_cases: |
| 71 | assert should_skip(version_str, comparator, ref_version_str) == expected |