From c3408ecc3c3dd95f6bd3211d534078603e4aae04 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Wed, 24 Jun 2026 15:40:46 +0200 Subject: [PATCH] refactor(brevo): utiliser DEVELOPMENT pour le mode sandbox Brevo (#87) Co-Authored-By: Claude Sonnet 4.6 --- .template.env | 1 - src/auth/mailer.py | 5 ++--- tests/auth/test_mailer.py | 1 - tests/auth/test_mailer_integration.py | 3 +-- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.template.env b/.template.env index f563a33..aa95306 100644 --- a/.template.env +++ b/.template.env @@ -37,6 +37,5 @@ APP_BASE_URL=http://localhost:8050 BREVO_API_KEY= # clé API transactionnelle Brevo BREVO_TEMPLATE_VERIFY_ID= # ID numérique du template "vérification d'adresse" BREVO_TEMPLATE_RESET_ID= # ID numérique du template "réinitialisation mot de passe" -BREVO_SANDBOX= # mettre "true" pour valider sans délivrer (dev / intégration) MAIL_FROM=noreply@decp.info # expéditeur (doit être un expéditeur vérifié dans Brevo) MAIL_FROM_NAME=decp.info # nom d'expéditeur diff --git a/src/auth/mailer.py b/src/auth/mailer.py index 26c4a9a..165b34b 100644 --- a/src/auth/mailer.py +++ b/src/auth/mailer.py @@ -7,7 +7,7 @@ from brevo import ( ) from brevo.core.api_error import ApiError -from src.utils import logger +from src.utils import DEVELOPMENT, logger _client: Brevo | None = None @@ -16,8 +16,7 @@ def init_mailer() -> None: """Construit le client Brevo à partir des variables d'environnement.""" global _client api_key = os.getenv("BREVO_API_KEY", "") - sandbox = os.getenv("BREVO_SANDBOX", "").lower() == "true" - headers = {"X-Sib-Sandbox": "drop"} if sandbox else None + headers = {"X-Sib-Sandbox": "drop"} if DEVELOPMENT else None _client = Brevo(api_key=api_key, headers=headers) diff --git a/tests/auth/test_mailer.py b/tests/auth/test_mailer.py index 271be2d..b0fc583 100644 --- a/tests/auth/test_mailer.py +++ b/tests/auth/test_mailer.py @@ -50,7 +50,6 @@ def test_send_reset_email(fake_client): def test_init_mailer_builds_client(monkeypatch): monkeypatch.setenv("BREVO_API_KEY", "test-key") - monkeypatch.delenv("BREVO_SANDBOX", raising=False) monkeypatch.setattr(mailer, "_client", None) mailer.init_mailer() assert mailer._client is not None diff --git a/tests/auth/test_mailer_integration.py b/tests/auth/test_mailer_integration.py index 05bd7c8..f99f1f3 100644 --- a/tests/auth/test_mailer_integration.py +++ b/tests/auth/test_mailer_integration.py @@ -12,8 +12,7 @@ pytestmark = pytest.mark.integration reason="BREVO_API_KEY absent — test d'intégration Brevo ignoré", ) def test_send_verification_email_sandbox(monkeypatch): - # Force le mode sandbox : Brevo valide la requête sans délivrer. - monkeypatch.setenv("BREVO_SANDBOX", "true") + # DEVELOPMENT=true (défini dans pytest.ini_options) active le mode sandbox Brevo. monkeypatch.setenv("APP_BASE_URL", "http://localhost:8050") mailer.init_mailer() # Ne doit pas lever : l'API Brevo accepte la requête en sandbox.