from pathlib import Path import pytest from app.config import get_settings def test_defaults(): s = get_settings() assert s.horizon_days == 548 assert s.gui_user == "admin" def test_env_file_defaults_to_container_mount_path(monkeypatch): monkeypatch.delenv("FB_ENV_FILE", raising=False) get_settings.cache_clear() try: assert get_settings().env_file == Path("/data/.env") finally: get_settings.cache_clear() def test_env_file_overridable_via_env_var(monkeypatch, tmp_path): custom = tmp_path / "custom.env" monkeypatch.setenv("FB_ENV_FILE", str(custom)) get_settings.cache_clear() try: assert get_settings().env_file == custom finally: get_settings.cache_clear() def test_grafana_url_default(monkeypatch): monkeypatch.delenv("FB_GRAFANA_URL", raising=False) get_settings.cache_clear() try: assert get_settings().grafana_url == "http://localhost:3000" finally: get_settings.cache_clear() def test_grafana_public_url_default(monkeypatch): monkeypatch.delenv("FB_GRAFANA_PUBLIC_URL", raising=False) get_settings.cache_clear() try: assert get_settings().grafana_public_url == "" finally: get_settings.cache_clear() def test_grafana_public_url_from_env(monkeypatch): monkeypatch.setenv("FB_GRAFANA_PUBLIC_URL", "https://fb.example.de/grafana/") get_settings.cache_clear() try: assert get_settings().grafana_public_url == "https://fb.example.de/grafana/" finally: get_settings.cache_clear() def test_session_cookie_secure_default_false(monkeypatch): monkeypatch.delenv("FB_SESSION_COOKIE_SECURE", raising=False) get_settings.cache_clear() try: assert get_settings().session_cookie_secure is False finally: get_settings.cache_clear() @pytest.mark.parametrize("val,expected", [ ("true", True), ("True", True), ("1", True), ("yes", True), ("on", True), ("false", False), ("0", False), ("", False), ("nope", False), ]) def test_session_cookie_secure_parsing(monkeypatch, val, expected): monkeypatch.setenv("FB_SESSION_COOKIE_SECURE", val) get_settings.cache_clear() try: assert get_settings().session_cookie_secure is expected finally: get_settings.cache_clear()