Files
FabledSteward/tests/test_config.py
T
2026-04-13 17:13:55 -04:00

40 lines
1.4 KiB
Python

import os
import textwrap
import pytest
from roundtable.config import load_bootstrap
def test_load_bootstrap_from_yaml(tmp_path):
cfg_file = tmp_path / "config.yaml"
cfg_file.write_text(textwrap.dedent("""\
database:
url: postgresql+asyncpg://user:pass@localhost/roundtable
secret_key: test-secret
"""))
cfg = load_bootstrap(cfg_file)
assert cfg["database_url"] == "postgresql+asyncpg://user:pass@localhost/roundtable"
assert cfg["secret_key"] == "test-secret"
def test_env_var_database_url_overrides_yaml(tmp_path, monkeypatch):
cfg_file = tmp_path / "config.yaml"
cfg_file.write_text("database:\n url: original\nsecret_key: s\n")
monkeypatch.setenv("FABLEDSCRYER_DATABASE_URL", "overridden")
cfg = load_bootstrap(cfg_file)
assert cfg["database_url"] == "overridden"
def test_env_var_secret_key_overrides_yaml(tmp_path, monkeypatch):
cfg_file = tmp_path / "config.yaml"
cfg_file.write_text("database:\n url: x\nsecret_key: from-yaml\n")
monkeypatch.setenv("FABLEDSCRYER_SECRET_KEY", "from-env")
cfg = load_bootstrap(cfg_file)
assert cfg["secret_key"] == "from-env"
def test_missing_database_url_raises(tmp_path):
cfg_file = tmp_path / "config.yaml"
cfg_file.write_text("secret_key: s\n")
with pytest.raises(ValueError, match="Database URL is required"):
load_bootstrap(cfg_file)