|
1 | | -import typing |
| 1 | +from typing import Any, Optional |
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from pytest_mock import MockerFixture |
| 5 | +from pydantic import ValidationError |
5 | 6 |
|
6 | | -from edge_proxy.settings import get_settings |
| 7 | +from edge_proxy.settings import get_settings, AppSettings |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize( |
| 11 | + "client_side_key,server_side_key,expected_exception", |
| 12 | + [ |
| 13 | + ("abc123", "ser.456", None), |
| 14 | + ("abc123", "456", ValidationError), |
| 15 | + ("abc123", "", ValidationError), |
| 16 | + ("", "ser.456", ValidationError), |
| 17 | + ], |
| 18 | +) |
| 19 | +def test_client_side_key_validation( |
| 20 | + client_side_key: str, server_side_key: str, expected_exception: Optional[Exception] |
| 21 | +) -> None: |
| 22 | + try: |
| 23 | + AppSettings( |
| 24 | + environment_key_pairs=[ |
| 25 | + {"server_side_key": server_side_key, "client_side_key": client_side_key} |
| 26 | + ] |
| 27 | + ) |
| 28 | + except expected_exception: |
| 29 | + pass |
7 | 30 |
|
8 | 31 |
|
9 | 32 | @pytest.mark.parametrize( |
|
12 | 35 | ( |
13 | 36 | { |
14 | 37 | "environment_key_pairs": [ |
15 | | - {"server_side_key": "abc123", "client_side_key": "ser.def456"} |
| 38 | + {"server_side_key": "ser.abc123", "client_side_key": "def456"} |
16 | 39 | ], |
17 | 40 | "api_poll_frequency": 10, |
18 | 41 | "api_poll_timeout": 10, |
|
23 | 46 | ( |
24 | 47 | { |
25 | 48 | "environment_key_pairs": [ |
26 | | - {"server_side_key": "abc123", "client_side_key": "ser.def456"} |
| 49 | + {"server_side_key": "ser.abc123", "client_side_key": "def456"} |
27 | 50 | ], |
28 | 51 | "api_poll_frequency_seconds": 10, |
29 | 52 | "api_poll_timeout_seconds": 10, |
|
35 | 58 | ) |
36 | 59 | def test_settings_are_loaded_correctly( |
37 | 60 | mocker: MockerFixture, |
38 | | - config_file_json: dict[str, typing.Any], |
39 | | - expected_config: dict[str, typing.Any], |
| 61 | + config_file_json: dict[str, Any], |
| 62 | + expected_config: dict[str, Any], |
40 | 63 | ) -> None: |
41 | 64 | """ |
42 | 65 | Parametrized test which accepts a raw json config file, and a dictionary representing the |
|
0 commit comments