diff --git a/src/ntr_fetcher/config.py b/src/ntr_fetcher/config.py index 17ddec7..2afa83b 100644 --- a/src/ntr_fetcher/config.py +++ b/src/ntr_fetcher/config.py @@ -12,3 +12,11 @@ class Settings(BaseSettings): soundcloud_user: str = "nicktherat" show_day: int = 2 show_hour: int = 22 + + web_user: str | None = None + web_password: str | None = None + secret_key: str | None = None + + @property + def dashboard_enabled(self) -> bool: + return all([self.web_user, self.web_password, self.secret_key]) diff --git a/tests/test_config.py b/tests/test_config.py index 16987d1..a7e5f92 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -28,3 +28,27 @@ def test_settings_admin_token_required(): import pytest with pytest.raises(Exception): Settings() + + +def test_dashboard_config_absent(monkeypatch): + monkeypatch.setenv("NTR_ADMIN_TOKEN", "tok") + monkeypatch.delenv("NTR_WEB_USER", raising=False) + monkeypatch.delenv("NTR_WEB_PASSWORD", raising=False) + monkeypatch.delenv("NTR_SECRET_KEY", raising=False) + s = Settings() + assert s.web_user is None + assert s.web_password is None + assert s.secret_key is None + assert s.dashboard_enabled is False + + +def test_dashboard_config_present(monkeypatch): + monkeypatch.setenv("NTR_ADMIN_TOKEN", "tok") + monkeypatch.setenv("NTR_WEB_USER", "nick") + monkeypatch.setenv("NTR_WEB_PASSWORD", "secret") + monkeypatch.setenv("NTR_SECRET_KEY", "signme") + s = Settings() + assert s.web_user == "nick" + assert s.web_password == "secret" + assert s.secret_key == "signme" + assert s.dashboard_enabled is True