f8b82b65a3
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
import os
|
|
import textwrap
|
|
import pytest
|
|
from fablednetmon.config import load_config
|
|
|
|
def test_load_minimal_config(tmp_path):
|
|
cfg_file = tmp_path / "config.yaml"
|
|
cfg_file.write_text(textwrap.dedent("""\
|
|
database:
|
|
url: postgresql+asyncpg://user:pass@localhost/fablednetmon
|
|
secret_key: test-secret
|
|
"""))
|
|
cfg = load_config(cfg_file)
|
|
assert cfg["database"]["url"] == "postgresql+asyncpg://user:pass@localhost/fablednetmon"
|
|
assert cfg["secret_key"] == "test-secret"
|
|
|
|
def test_env_var_overrides_scalar(tmp_path, monkeypatch):
|
|
cfg_file = tmp_path / "config.yaml"
|
|
cfg_file.write_text("database:\n url: original\nsecret_key: s\n")
|
|
monkeypatch.setenv("FABLEDNETMON_DATABASE__URL", "overridden")
|
|
cfg = load_config(cfg_file)
|
|
assert cfg["database"]["url"] == "overridden"
|
|
|
|
def test_env_var_does_not_override_list(tmp_path, monkeypatch):
|
|
cfg_file = tmp_path / "config.yaml"
|
|
cfg_file.write_text("smtp:\n recipients:\n - a@b.com\nsecret_key: s\ndatabase:\n url: x\n")
|
|
monkeypatch.setenv("FABLEDNETMON_SMTP__RECIPIENTS", "bad")
|
|
cfg = load_config(cfg_file)
|
|
assert cfg["smtp"]["recipients"] == ["a@b.com"]
|
|
|
|
def test_missing_required_key_raises(tmp_path):
|
|
cfg_file = tmp_path / "config.yaml"
|
|
cfg_file.write_text("{}")
|
|
with pytest.raises(ValueError, match="secret_key"):
|
|
load_config(cfg_file)
|