Réactivation de l'env MAIL_SUPPRESS_SEND
This commit is contained in:
@@ -45,6 +45,9 @@ BREVO_TEMPLATE_VERIFY_ID= # ID numérique du template "vérification
|
||||
BREVO_TEMPLATE_RESET_ID= # ID numérique du template "réinitialisation mot de passe"
|
||||
MAIL_FROM=noreply@colibre.fr # expéditeur (doit être un expéditeur vérifié dans Brevo)
|
||||
MAIL_FROM_NAME=colibre # nom d'expéditeur
|
||||
# Active/désactive le mode sandbox Brevo (X-Sib-Sandbox: drop) indépendamment de DEVELOPMENT.
|
||||
# Si non défini, suit DEVELOPMENT (sandbox actif par défaut en dev/tests).
|
||||
MAIL_SUPPRESS_SEND=
|
||||
|
||||
# Sauvegarde de users.sqlite vers un stockage S3-compatible
|
||||
S3_ENDPOINT_URL=https://s3.exemple.net
|
||||
|
||||
+21
-1
@@ -37,9 +37,29 @@ def _template_id(env_var: str) -> int:
|
||||
return int(raw)
|
||||
|
||||
|
||||
def _suppress_send() -> bool:
|
||||
raw = os.getenv("MAIL_SUPPRESS_SEND")
|
||||
if raw is not None:
|
||||
return raw.lower() == "true"
|
||||
return DEVELOPMENT
|
||||
|
||||
|
||||
def _send_template(template_id: int, recipient: str, params: dict) -> None:
|
||||
assert _client is not None, "Mailer non initialisé (init_mailer() non appelé)"
|
||||
sandbox_headers = {"X-Sib-Sandbox": "drop"} if DEVELOPMENT else None
|
||||
suppress = _suppress_send()
|
||||
if suppress:
|
||||
cause = (
|
||||
"MAIL_SUPPRESS_SEND=true"
|
||||
if os.getenv("MAIL_SUPPRESS_SEND") is not None
|
||||
else "DEVELOPMENT=true"
|
||||
)
|
||||
logger.warning(
|
||||
"Email en mode sandbox (%s) — non délivré à %s (template %s)",
|
||||
cause,
|
||||
recipient,
|
||||
template_id,
|
||||
)
|
||||
sandbox_headers = {"X-Sib-Sandbox": "drop"} if suppress else None
|
||||
try:
|
||||
_client.transactional_emails.send_transac_email(
|
||||
template_id=template_id,
|
||||
|
||||
@@ -40,6 +40,26 @@ def test_send_verification_email(fake_client):
|
||||
assert call["headers"] == {"X-Sib-Sandbox": "drop"} # DEVELOPMENT=true en tests
|
||||
|
||||
|
||||
def test_mail_suppress_send_true_forces_sandbox_even_outside_development(
|
||||
fake_client, monkeypatch
|
||||
):
|
||||
monkeypatch.setattr(mailer, "DEVELOPMENT", False)
|
||||
monkeypatch.setenv("MAIL_SUPPRESS_SEND", "true")
|
||||
mailer.send_verification_email("a@b.c", "TOKEN123")
|
||||
call = fake_client.transactional_emails.calls[0]
|
||||
assert call["headers"] == {"X-Sib-Sandbox": "drop"}
|
||||
|
||||
|
||||
def test_mail_suppress_send_false_disables_sandbox_even_in_development(
|
||||
fake_client, monkeypatch
|
||||
):
|
||||
monkeypatch.setattr(mailer, "DEVELOPMENT", True)
|
||||
monkeypatch.setenv("MAIL_SUPPRESS_SEND", "false")
|
||||
mailer.send_verification_email("a@b.c", "TOKEN123")
|
||||
call = fake_client.transactional_emails.calls[0]
|
||||
assert call["headers"] is None
|
||||
|
||||
|
||||
def test_send_reset_email(fake_client):
|
||||
mailer.send_reset_email("a@b.c", "RESET456")
|
||||
calls = fake_client.transactional_emails.calls
|
||||
|
||||
Reference in New Issue
Block a user