57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
from config import Settings, get_settings
|
|
|
|
|
|
def test_settings_default_values():
|
|
"""Vérifie les valeurs par défaut"""
|
|
settings = Settings()
|
|
assert settings.cors_origins == "http://localhost:5173"
|
|
assert settings.app_name == "Dough Calculator"
|
|
assert settings.debug is False
|
|
|
|
def test_settings_from_env(monkeypatch):
|
|
"""Vérifie le chargement depuis variables d'environnement"""
|
|
monkeypatch.setenv("CORS_ORIGINS", "https://example.com,https://test.com")
|
|
monkeypatch.setenv("APP_NAME", "Test App")
|
|
monkeypatch.setenv("DEBUG", "true")
|
|
|
|
# Vider le cache pour forcer le rechargement
|
|
get_settings.cache_clear()
|
|
|
|
settings = get_settings()
|
|
assert settings.cors_origins == "https://example.com,https://test.com"
|
|
assert settings.app_name == "Test App"
|
|
assert settings.debug is True
|
|
|
|
def test_cors_origins_parsing():
|
|
"""Vérifie que les origines CORS sont correctement parsées"""
|
|
settings = Settings(cors_origins="http://localhost:3000,https://prod.com")
|
|
origins = [origin.strip() for origin in settings.cors_origins.split(",")]
|
|
|
|
assert len(origins) == 2
|
|
assert "http://localhost:3000" in origins
|
|
assert "https://prod.com" in origins
|
|
|
|
def test_settings_cache():
|
|
"""Vérifie que le cache fonctionne"""
|
|
get_settings.cache_clear()
|
|
|
|
settings1 = get_settings()
|
|
settings2 = get_settings()
|
|
|
|
# Même instance en mémoire grâce au cache
|
|
assert settings1 is settings2
|
|
|
|
def test_env_file_loading(tmp_path, monkeypatch):
|
|
"""Vérifie le chargement depuis fichier .env"""
|
|
# Créer un fichier .env temporaire
|
|
env_file = tmp_path / ".env"
|
|
env_file.write_text("CORS_ORIGINS=https://from-file.com\nDEBUG=true")
|
|
|
|
# Changer le répertoire de travail
|
|
monkeypatch.chdir(tmp_path)
|
|
get_settings.cache_clear()
|
|
|
|
settings = Settings()
|
|
assert settings.cors_origins == "https://from-file.com"
|
|
assert settings.debug is True
|