Files
transcription/tests/test_config_isolation.py
T
Jim Lancaster 6f4accf275
Quality Gate / gate (push) Successful in 2m38s
Implement rec - Phase 4 complete
2026-09-02 16:23:09 -05:00

50 lines
1.7 KiB
Python

"""Suite-wide isolation of `Settings` from developer environment files."""
from __future__ import annotations
from pathlib import Path
import transcription.config as config_module
from transcription.config import Settings
from transcription.config import resolve_settings_env_file_path
def test_settings_defaults_are_not_overridden_by_a_local_env_file():
"""A bare `Settings(...)` must observe declared defaults, not developer machine state."""
settings = Settings(openrouter_api_key="test-key")
assert settings.environment == "development"
assert settings.log_dir == Path("./data/logs")
assert settings.host == "0.0.0.0"
assert settings.port == 8000
def test_explicit_env_file_still_loads(tmp_path):
"""Isolation must not disable env-file loading for tests that opt into it."""
env_path = tmp_path / ".env"
env_path.write_text("PORT=9123\n", encoding="utf-8")
settings = Settings(openrouter_api_key="test-key", _env_file=env_path, _cli_parse_args=False)
assert settings.port == 9123
def test_settings_env_file_resolves_from_override_environment_variable(tmp_path, monkeypatch):
env_path = tmp_path / "custom.env"
env_path.write_text("PORT=9123\n", encoding="utf-8")
monkeypatch.setenv("ENV_FILE", str(env_path))
settings = Settings(openrouter_api_key="test-key", _cli_parse_args=False)
assert settings.port == 9123
def test_settings_default_env_path_is_anchored_to_project_root(tmp_path, monkeypatch):
monkeypatch.delenv("ENV_FILE", raising=False)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(config_module, "PROJECT_ROOT", tmp_path / "project-root")
resolved = resolve_settings_env_file_path()
assert resolved == tmp_path / "project-root" / ".env.production"