|
7 | 7 | UNKNOWN = Reason.UNKNOWN |
8 | 8 |
|
9 | 9 |
|
10 | | -@pytest.fixture(scope='session') |
11 | | -def strategy(): |
12 | | - strategy = Strategy( |
13 | | - authorized_licenses=['authorized 1', 'authorized 2'], |
14 | | - unauthorized_licenses=['unauthorized 1', 'unauthorized 2'], |
15 | | - authorized_packages={'whitelisted': '1'} |
16 | | - ) |
17 | | - return strategy |
| 10 | +# @pytest.fixture(scope="session") |
| 11 | +# def strategy(): |
| 12 | +# strategy = Strategy( |
| 13 | +# authorized_licenses=["authorized 1", "authorized 2"], |
| 14 | +# unauthorized_licenses=["unauthorized 1", "unauthorized 2"], |
| 15 | +# authorized_packages={"whitelisted": "1"}, |
| 16 | +# ) |
| 17 | +# return strategy |
18 | 18 |
|
19 | 19 |
|
20 | | -@pytest.fixture(scope='session') |
| 20 | +@pytest.fixture(scope="session") |
21 | 21 | def packages(): |
22 | 22 | return [ |
23 | 23 | { |
24 | | - 'name': 'auth_one', 'version': '1', |
25 | | - 'licenses': ['authorized 1'], |
26 | | - }, { |
27 | | - 'name': 'auth_one_and_two', 'version': '2', |
28 | | - 'licenses': ['authorized 1', 'authorized 2'], |
29 | | - }, { |
30 | | - 'name': 'auth_one_unauth_one', 'version': '1', |
31 | | - 'licenses': ['authorized 1', 'unauthorized 1'], |
32 | | - }, { |
33 | | - 'name': 'unauth_one', 'version': '2', |
34 | | - 'licenses': ['unauthorized 1'], |
35 | | - }, { |
36 | | - 'name': 'whitelisted', 'version': '1', |
37 | | - 'licenses': ['unauthorized 1'], |
38 | | - }, { |
39 | | - 'name': 'whitelisted', 'version': '2', |
40 | | - 'licenses': ['unauthorized 1'], |
41 | | - }, { |
42 | | - 'name': 'auth_one_unknown', 'version': '1', |
43 | | - 'licenses': ['authorized 1', 'unknown'], |
44 | | - }, { |
45 | | - 'name': 'unknown', 'version': '3', |
46 | | - 'licenses': ['unknown'], |
| 24 | + "name": "auth_one", |
| 25 | + "version": "1", |
| 26 | + "licenses": ["authorized 1"], |
| 27 | + }, |
| 28 | + { |
| 29 | + "name": "auth_one_and_two", |
| 30 | + "version": "2", |
| 31 | + "licenses": ["authorized 1", "authorized 2"], |
| 32 | + }, |
| 33 | + { |
| 34 | + "name": "auth_one_unauth_one", |
| 35 | + "version": "1", |
| 36 | + "licenses": ["authorized 1", "unauthorized 1"], |
| 37 | + }, |
| 38 | + { |
| 39 | + "name": "unauth_one", |
| 40 | + "version": "2", |
| 41 | + "licenses": ["unauthorized 1"], |
| 42 | + }, |
| 43 | + { |
| 44 | + "name": "whitelisted", |
| 45 | + "version": "1", |
| 46 | + "licenses": ["unauthorized 1"], |
| 47 | + }, |
| 48 | + { |
| 49 | + "name": "whitelisted", |
| 50 | + "version": "2", |
| 51 | + "licenses": ["unauthorized 1"], |
| 52 | + }, |
| 53 | + { |
| 54 | + "name": "auth_one_unknown", |
| 55 | + "version": "1", |
| 56 | + "licenses": ["authorized 1", "unknown"], |
| 57 | + }, |
| 58 | + { |
| 59 | + "name": "unknown", |
| 60 | + "version": "3", |
| 61 | + "licenses": ["unknown"], |
47 | 62 | }, |
48 | 63 | ] |
49 | 64 |
|
50 | 65 |
|
51 | 66 | @pytest.mark.parametrize( |
52 | | - ('level', 'reasons'), |
53 | | - [(Level.STANDARD, [OK, OK, OK, UNAUTH, OK, UNAUTH, OK, UNKNOWN]), |
54 | | - (Level.CAUTIOUS, [OK, OK, UNAUTH, UNAUTH, OK, UNAUTH, OK, UNKNOWN]), |
55 | | - (Level.PARANOID, [OK, OK, UNAUTH, UNAUTH, OK, UNAUTH, UNKNOWN, UNKNOWN]), |
56 | | - ], |
57 | | - ids=[level.name for level in Level]) |
58 | | -def test_check_package(strategy, packages, level, reasons): |
| 67 | + ("strategy_params", "as_regex"), |
| 68 | + [ |
| 69 | + ( |
| 70 | + dict( |
| 71 | + authorized_licenses=["authorized 1", "authorized 2"], |
| 72 | + unauthorized_licenses=["unauthorized 1", "unauthorized 2"], |
| 73 | + authorized_packages={"whitelisted": "1"}, |
| 74 | + ), |
| 75 | + False, |
| 76 | + ), |
| 77 | + ( |
| 78 | + dict( |
| 79 | + authorized_licenses=[r"\bauthorized"], |
| 80 | + unauthorized_licenses=[r"\bunauthorized"], |
| 81 | + authorized_packages={"whitelisted": "1"}, |
| 82 | + ), |
| 83 | + True, |
| 84 | + ), |
| 85 | + ], |
| 86 | +) |
| 87 | +@pytest.mark.parametrize( |
| 88 | + ("level", "reasons"), |
| 89 | + [ |
| 90 | + (Level.STANDARD, [OK, OK, OK, UNAUTH, OK, UNAUTH, OK, UNKNOWN]), |
| 91 | + (Level.CAUTIOUS, [OK, OK, UNAUTH, UNAUTH, OK, UNAUTH, OK, UNKNOWN]), |
| 92 | + (Level.PARANOID, [OK, OK, UNAUTH, UNAUTH, OK, UNAUTH, UNKNOWN, UNKNOWN]), |
| 93 | + ], |
| 94 | + ids=[level.name for level in Level], |
| 95 | +) |
| 96 | +def test_check_package(strategy_params, packages, level, reasons, as_regex): |
| 97 | + strategy = Strategy(**strategy_params) |
59 | 98 | for package, reason in zip(packages, reasons): |
60 | | - assert check_package(strategy, package, level) is reason |
| 99 | + assert check_package(strategy, package, level, as_regex) is reason |
0 commit comments