|
1 | | -import typing |
| 1 | +from typing import Any, Optional |
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from pytest_mock import MockerFixture |
|
7 | 7 | from edge_proxy.settings import get_settings, AppSettings |
8 | 8 |
|
9 | 9 |
|
10 | | -def test_client_side_key_validation() -> None: |
11 | | - """ |
12 | | - Test that client_side_key is properly validated. |
13 | | - """ |
14 | | - # Valid |
15 | | - AppSettings( |
16 | | - environment_key_pairs=[ |
17 | | - {"server_side_key": "ser.abc123", "client_side_key": "def456"} |
18 | | - ] |
19 | | - ) |
20 | | - |
21 | | - # Missing client_side_key |
22 | | - with pytest.raises(ValidationError): |
23 | | - AppSettings( |
24 | | - environment_key_pairs=[ |
25 | | - {"server_side_key": "ser.abc123", "client_side_key": ""} |
26 | | - ] |
27 | | - ) |
28 | | - |
29 | | - # Invalid server_side_key |
30 | | - with pytest.raises(ValidationError): |
| 10 | +@pytest.mark.parametrize( |
| 11 | + "client_side_key,server_side_key,expected_exception", |
| 12 | + [ |
| 13 | + ("abc123", "ser.456", None), |
| 14 | + ("", "ser.456", ValidationError), |
| 15 | + ("abc123", "456", ValidationError), |
| 16 | + ], |
| 17 | +) |
| 18 | +def test_client_side_key_validation( |
| 19 | + client_side_key: str, server_side_key: str, expected_exception: Optional[Exception] |
| 20 | +) -> None: |
| 21 | + try: |
31 | 22 | AppSettings( |
32 | 23 | environment_key_pairs=[ |
33 | | - {"server_side_key": "abc123", "client_side_key": "abc123"} |
| 24 | + {"server_side_key": server_side_key, "client_side_key": client_side_key} |
34 | 25 | ] |
35 | 26 | ) |
| 27 | + except expected_exception: |
| 28 | + pass |
36 | 29 |
|
37 | 30 |
|
38 | 31 | @pytest.mark.parametrize( |
@@ -64,8 +57,8 @@ def test_client_side_key_validation() -> None: |
64 | 57 | ) |
65 | 58 | def test_settings_are_loaded_correctly( |
66 | 59 | mocker: MockerFixture, |
67 | | - config_file_json: dict[str, typing.Any], |
68 | | - expected_config: dict[str, typing.Any], |
| 60 | + config_file_json: dict[str, Any], |
| 61 | + expected_config: dict[str, Any], |
69 | 62 | ) -> None: |
70 | 63 | """ |
71 | 64 | Parametrized test which accepts a raw json config file, and a dictionary representing the |
|
0 commit comments