Skip to content

Commit 04d4d01

Browse files
committed
add config validation tests
1 parent f111525 commit 04d4d01

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
3+
from src.utils import config
4+
from src.utils.validate_config import validate_config
5+
6+
7+
def _set_base_config(monkeypatch: pytest.MonkeyPatch):
8+
monkeypatch.setattr(config, "UPDATE_STRATEGY", "SEQUENTIAL")
9+
monkeypatch.setattr(config, "UPDATE_INTERVAL", "30d")
10+
monkeypatch.setattr(config, "REGION", None)
11+
12+
13+
def test_validate_config_accepts_valid_configuration(monkeypatch: pytest.MonkeyPatch):
14+
_set_base_config(monkeypatch)
15+
16+
validate_config()
17+
18+
19+
@pytest.mark.parametrize("strategy", ["parallel", "FULL", ""])
20+
def test_validate_config_rejects_invalid_strategy(monkeypatch: pytest.MonkeyPatch, strategy: str):
21+
_set_base_config(monkeypatch)
22+
monkeypatch.setattr(config, "UPDATE_STRATEGY", strategy)
23+
24+
with pytest.raises(ValueError, match=f"Invalid UPDATE_STRATEGY: '{strategy}'"):
25+
validate_config()
26+
27+
28+
@pytest.mark.parametrize("interval", ["30", "d30", "30w", "1D", ""])
29+
def test_validate_config_rejects_invalid_interval(monkeypatch: pytest.MonkeyPatch, interval: str):
30+
_set_base_config(monkeypatch)
31+
monkeypatch.setattr(config, "UPDATE_INTERVAL", interval)
32+
33+
with pytest.raises(ValueError, match=f"Invalid UPDATE_INTERVAL format: '{interval}'"):
34+
validate_config()
35+
36+
37+
def test_validate_config_rejects_invalid_region(monkeypatch: pytest.MonkeyPatch):
38+
_set_base_config(monkeypatch)
39+
monkeypatch.setattr(config, "REGION", "atlantis")
40+
41+
with pytest.raises(ValueError, match="Invalid REGION: 'atlantis'"):
42+
validate_config()
43+
44+
45+
def test_validate_config_reports_multiple_errors(monkeypatch: pytest.MonkeyPatch):
46+
_set_base_config(monkeypatch)
47+
monkeypatch.setattr(config, "UPDATE_STRATEGY", "WRONG")
48+
monkeypatch.setattr(config, "UPDATE_INTERVAL", "hourly")
49+
monkeypatch.setattr(config, "REGION", "atlantis")
50+
51+
with pytest.raises(ValueError) as exc_info:
52+
validate_config()
53+
54+
message = str(exc_info.value)
55+
56+
assert "Configuration validation failed:" in message
57+
assert "Invalid UPDATE_STRATEGY: 'WRONG'" in message
58+
assert "Invalid UPDATE_INTERVAL format: 'hourly'" in message
59+
assert "Invalid REGION: 'atlantis'" in message

0 commit comments

Comments
 (0)