from __future__ import annotations

"""Tests for environment-backed settings parsing."""

import importlib


def test_env_bool_handles_truthy_and_falsey(monkeypatch) -> None:
    import atlas_portal.settings as settings

    monkeypatch.setenv("TEST_FLAG", "YES")
    assert settings._env_bool("TEST_FLAG") is True
    monkeypatch.setenv("TEST_FLAG", "0")
    assert settings._env_bool("TEST_FLAG") is False


def test_settings_reload_picks_up_environment(monkeypatch) -> None:
    monkeypatch.setenv("KEYCLOAK_ENABLED", "true")
    monkeypatch.setenv("PORTAL_ADMIN_USERS", "alice,bob")

    import atlas_portal.settings as settings

    reloaded = importlib.reload(settings)

    assert reloaded.KEYCLOAK_ENABLED is True
    assert reloaded.PORTAL_ADMIN_USERS == ["alice", "bob"]
