refactor(brevo): utiliser DEVELOPMENT pour le mode sandbox Brevo (#87)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Colin Maudry
2026-06-24 15:40:46 +02:00
parent c0927c718d
commit c3408ecc3c
4 changed files with 3 additions and 7 deletions
-1
View File
@@ -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
+2 -3
View File
@@ -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)
-1
View File
@@ -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
+1 -2
View File
@@ -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.