Brevo: Rename SendinBlue to Brevo

- Replace "SendinBlue" with "Brevo"
  throughout the code.
- Maintain deprecated compatibility
  versions on the old names/URLs.
  (Split into separate commit
  to make renamed files more
  obvious.)
- Update docs to reflect change,
  provide migration advice.
- Update integration workflow.
This commit is contained in:
Mike Edmunds
2024-03-11 18:46:52 -07:00
parent 14d451659e
commit c7ee59c3ca
12 changed files with 326 additions and 197 deletions

View File

@@ -32,19 +32,16 @@ from .utils import (
)
@tag("sendinblue")
@tag("brevo")
@override_settings(
EMAIL_BACKEND="anymail.backends.sendinblue.EmailBackend",
ANYMAIL={"SENDINBLUE_API_KEY": "test_api_key"},
EMAIL_BACKEND="anymail.backends.brevo.EmailBackend",
ANYMAIL={"BREVO_API_KEY": "test_api_key"},
)
class SendinBlueBackendMockAPITestCase(RequestsBackendMockAPITestCase):
# SendinBlue v3 success responses are empty
class BrevoBackendMockAPITestCase(RequestsBackendMockAPITestCase):
DEFAULT_RAW_RESPONSE = (
b'{"messageId":"<201801020304.1234567890@smtp-relay.mailin.fr>"}'
)
DEFAULT_STATUS_CODE = (
201 # SendinBlue v3 uses '201 Created' for success (in most cases)
)
DEFAULT_STATUS_CODE = 201 # Brevo v3 uses '201 Created' for success (in most cases)
def setUp(self):
super().setUp()
@@ -54,8 +51,8 @@ class SendinBlueBackendMockAPITestCase(RequestsBackendMockAPITestCase):
)
@tag("sendinblue")
class SendinBlueBackendStandardEmailTests(SendinBlueBackendMockAPITestCase):
@tag("brevo")
class BrevoBackendStandardEmailTests(BrevoBackendMockAPITestCase):
"""Test backend support for Django standard email features"""
def test_send_mail(self):
@@ -204,7 +201,7 @@ class SendinBlueBackendStandardEmailTests(SendinBlueBackendMockAPITestCase):
)
def test_multiple_reply_to(self):
# SendinBlue v3 only allows a single reply address
# Brevo v3 only allows a single reply address
self.message.reply_to = [
'"Reply recipient" <reply@example.com',
"reply2@example.com",
@@ -274,7 +271,7 @@ class SendinBlueBackendStandardEmailTests(SendinBlueBackendMockAPITestCase):
)
def test_embedded_images(self):
# SendinBlue doesn't support inline image
# Brevo doesn't support inline image
# inline image are just added as a content attachment
image_filename = SAMPLE_IMAGE_FILENAME
@@ -339,7 +336,7 @@ class SendinBlueBackendStandardEmailTests(SendinBlueBackendMockAPITestCase):
def test_api_failure(self):
self.set_mock_response(status_code=400)
with self.assertRaisesMessage(AnymailAPIError, "SendinBlue API response 400"):
with self.assertRaisesMessage(AnymailAPIError, "Brevo API response 400"):
mail.send_mail("Subject", "Body", "from@example.com", ["to@example.com"])
# Make sure fail_silently is respected
@@ -373,12 +370,12 @@ class SendinBlueBackendStandardEmailTests(SendinBlueBackendMockAPITestCase):
self.message.send()
@tag("sendinblue")
class SendinBlueBackendAnymailFeatureTests(SendinBlueBackendMockAPITestCase):
@tag("brevo")
class BrevoBackendAnymailFeatureTests(BrevoBackendMockAPITestCase):
"""Test backend support for Anymail added features"""
def test_envelope_sender(self):
# SendinBlue does not have a way to change envelope sender.
# Brevo does not have a way to change envelope sender.
self.message.envelope_sender = "anything@bounces.example.com"
with self.assertRaisesMessage(AnymailUnsupportedFeature, "envelope_sender"):
self.message.send()
@@ -459,7 +456,7 @@ class SendinBlueBackendAnymailFeatureTests(SendinBlueBackendMockAPITestCase):
self.message.send()
def test_template_id(self):
# subject, body, and from_email must be None for SendinBlue template send:
# subject, body, and from_email must be None for Brevo template send:
message = mail.EmailMessage(
subject="My Subject",
body=None,
@@ -470,7 +467,7 @@ class SendinBlueBackendAnymailFeatureTests(SendinBlueBackendMockAPITestCase):
bcc=["Recipient <bcc@example.com>"],
reply_to=["Recipient <reply@example.com>"],
)
# SendinBlue uses per-account numeric ID to identify templates:
# Brevo uses per-account numeric ID to identify templates:
message.template_id = 12
message.send()
data = self.get_api_call_json()
@@ -603,7 +600,7 @@ class SendinBlueBackendAnymailFeatureTests(SendinBlueBackendMockAPITestCase):
# noinspection PyUnresolvedReferences
def test_send_attaches_anymail_status(self):
"""The anymail_status should be attached to the message when it is sent"""
# the DEFAULT_RAW_RESPONSE above is the *only* success response SendinBlue
# the DEFAULT_RAW_RESPONSE above is the *only* success response Brevo
# returns, so no need to override it here
msg = mail.EmailMessage(
"Subject",
@@ -652,39 +649,37 @@ class SendinBlueBackendAnymailFeatureTests(SendinBlueBackendMockAPITestCase):
err = cm.exception
self.assertIsInstance(err, TypeError) # compatibility with json.dumps
# our added context:
self.assertIn("Don't know how to send this data to SendinBlue", str(err))
self.assertIn("Don't know how to send this data to Brevo", str(err))
# original message
self.assertRegex(str(err), r"Decimal.*is not JSON serializable")
@tag("sendinblue")
class SendinBlueBackendRecipientsRefusedTests(SendinBlueBackendMockAPITestCase):
@tag("brevo")
class BrevoBackendRecipientsRefusedTests(BrevoBackendMockAPITestCase):
"""
Should raise AnymailRecipientsRefused when *all* recipients are rejected or invalid
"""
# SendinBlue doesn't check email bounce or complaint lists at time of send --
# Brevo doesn't check email bounce or complaint lists at time of send --
# it always just queues the message. You'll need to listen for the "rejected"
# and "failed" events to detect refused recipients.
pass # not applicable to this backend
@tag("sendinblue")
class SendinBlueBackendSessionSharingTestCase(
SessionSharingTestCases, SendinBlueBackendMockAPITestCase
@tag("brevo")
class BrevoBackendSessionSharingTestCase(
SessionSharingTestCases, BrevoBackendMockAPITestCase
):
"""Requests session sharing tests"""
pass # tests are defined in SessionSharingTestCases
@tag("sendinblue")
@override_settings(EMAIL_BACKEND="anymail.backends.sendinblue.EmailBackend")
class SendinBlueBackendImproperlyConfiguredTests(AnymailTestMixin, SimpleTestCase):
@tag("brevo")
@override_settings(EMAIL_BACKEND="anymail.backends.brevo.EmailBackend")
class BrevoBackendImproperlyConfiguredTests(AnymailTestMixin, SimpleTestCase):
"""Test ESP backend without required settings in place"""
def test_missing_auth(self):
with self.assertRaisesRegex(
AnymailConfigurationError, r"\bSENDINBLUE_API_KEY\b"
):
with self.assertRaisesRegex(AnymailConfigurationError, r"\bBREVO_API_KEY\b"):
mail.send_mail("Subject", "Message", "from@example.com", ["to@example.com"])

View File

@@ -7,15 +7,15 @@ from responses.matchers import header_matcher
from anymail.exceptions import AnymailConfigurationError
from anymail.inbound import AnymailInboundMessage
from anymail.signals import AnymailInboundEvent
from anymail.webhooks.sendinblue import SendinBlueInboundWebhookView
from anymail.webhooks.brevo import BrevoInboundWebhookView
from .utils import sample_email_content, sample_image_content
from .webhook_cases import WebhookTestCase
@tag("sendinblue")
@override_settings(ANYMAIL_SENDINBLUE_API_KEY="test-api-key")
class SendinBlueInboundTestCase(WebhookTestCase):
@tag("brevo")
@override_settings(ANYMAIL_BREVO_API_KEY="test-api-key")
class BrevoInboundTestCase(WebhookTestCase):
def test_inbound_basics(self):
# Actual (sanitized) Brevo inbound message payload 7/2023
raw_event = {
@@ -54,16 +54,16 @@ class SendinBlueInboundTestCase(WebhookTestCase):
}
response = self.client.post(
"/anymail/sendinblue/inbound/",
"/anymail/brevo/inbound/",
content_type="application/json",
data={"items": [raw_event]},
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.inbound_handler,
sender=SendinBlueInboundWebhookView,
sender=BrevoInboundWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
# AnymailInboundEvent
event = kwargs["event"]
@@ -123,15 +123,15 @@ class SendinBlueInboundTestCase(WebhookTestCase):
}
}
self.client.post(
"/anymail/sendinblue/inbound/",
"/anymail/brevo/inbound/",
content_type="application/json",
data={"items": [raw_event]},
)
kwargs = self.assert_handler_called_once_with(
self.inbound_handler,
sender=SendinBlueInboundWebhookView,
sender=BrevoInboundWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
message = event.message
@@ -203,16 +203,16 @@ class SendinBlueInboundTestCase(WebhookTestCase):
)
response = self.client.post(
"/anymail/sendinblue/inbound/",
"/anymail/brevo/inbound/",
content_type="application/json",
data={"items": [raw_event]},
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.inbound_handler,
sender=SendinBlueInboundWebhookView,
sender=BrevoInboundWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
message = event.message
@@ -235,12 +235,12 @@ class SendinBlueInboundTestCase(WebhookTestCase):
def test_misconfigured_tracking(self):
errmsg = (
"You seem to have set SendinBlue's *tracking* webhook URL"
" to Anymail's SendinBlue *inbound* webhook URL."
"You seem to have set Brevo's *tracking* webhook URL"
" to Anymail's Brevo *inbound* webhook URL."
)
with self.assertRaisesMessage(AnymailConfigurationError, errmsg):
self.client.post(
"/anymail/sendinblue/inbound/",
"/anymail/brevo/inbound/",
content_type="application/json",
data={"event": "delivered"},
)

View File

@@ -10,39 +10,39 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin
ANYMAIL_TEST_SENDINBLUE_API_KEY = os.getenv("ANYMAIL_TEST_SENDINBLUE_API_KEY")
ANYMAIL_TEST_SENDINBLUE_DOMAIN = os.getenv("ANYMAIL_TEST_SENDINBLUE_DOMAIN")
ANYMAIL_TEST_BREVO_API_KEY = os.getenv("ANYMAIL_TEST_BREVO_API_KEY")
ANYMAIL_TEST_BREVO_DOMAIN = os.getenv("ANYMAIL_TEST_BREVO_DOMAIN")
@tag("sendinblue", "live")
@tag("brevo", "live")
@unittest.skipUnless(
ANYMAIL_TEST_SENDINBLUE_API_KEY and ANYMAIL_TEST_SENDINBLUE_DOMAIN,
"Set ANYMAIL_TEST_SENDINBLUE_API_KEY and ANYMAIL_TEST_SENDINBLUE_DOMAIN "
"environment variables to run SendinBlue integration tests",
ANYMAIL_TEST_BREVO_API_KEY and ANYMAIL_TEST_BREVO_DOMAIN,
"Set ANYMAIL_TEST_BREVO_API_KEY and ANYMAIL_TEST_BREVO_DOMAIN "
"environment variables to run Brevo integration tests",
)
@override_settings(
ANYMAIL_SENDINBLUE_API_KEY=ANYMAIL_TEST_SENDINBLUE_API_KEY,
ANYMAIL_SENDINBLUE_SEND_DEFAULTS=dict(),
EMAIL_BACKEND="anymail.backends.sendinblue.EmailBackend",
ANYMAIL_BREVO_API_KEY=ANYMAIL_TEST_BREVO_API_KEY,
ANYMAIL_BREVO_SEND_DEFAULTS=dict(),
EMAIL_BACKEND="anymail.backends.brevo.EmailBackend",
)
class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""SendinBlue v3 API integration tests
class BrevoBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""Brevo v3 API integration tests
SendinBlue doesn't have sandbox so these tests run
against the **live** SendinBlue API, using the
environment variable `ANYMAIL_TEST_SENDINBLUE_API_KEY` as the API key,
and `ANYMAIL_TEST_SENDINBLUE_DOMAIN` to construct sender addresses.
Brevo doesn't have sandbox so these tests run
against the **live** Brevo API, using the
environment variable `ANYMAIL_TEST_BREVO_API_KEY` as the API key,
and `ANYMAIL_TEST_BREVO_DOMAIN` to construct sender addresses.
If those variables are not set, these tests won't run.
https://developers.sendinblue.com/docs/faq#section-how-can-i-test-the-api-
https://developers.brevo.com/docs/faq#how-can-i-test-the-api
"""
def setUp(self):
super().setUp()
self.from_email = "from@%s" % ANYMAIL_TEST_SENDINBLUE_DOMAIN
self.from_email = "from@%s" % ANYMAIL_TEST_BREVO_DOMAIN
self.message = AnymailMessage(
"Anymail SendinBlue integration test",
"Anymail Brevo integration test",
"Text content",
self.from_email,
["test+to1@anymail.dev"],
@@ -50,7 +50,7 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
self.message.attach_alternative("<p>HTML content</p>", "text/html")
def test_simple_send(self):
# Example of getting the SendinBlue send status and message id from the message
# Example of getting the Brevo send status and message id from the message
sent_count = self.message.send()
self.assertEqual(sent_count, 1)
@@ -58,7 +58,7 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
sent_status = anymail_status.recipients["test+to1@anymail.dev"].status
message_id = anymail_status.recipients["test+to1@anymail.dev"].message_id
self.assertEqual(sent_status, "queued") # SendinBlue always queues
self.assertEqual(sent_status, "queued") # Brevo always queues
# Message-ID can be ...@smtp-relay.mail.fr or .sendinblue.com:
self.assertRegex(message_id, r"\<.+@.+\>")
# set of all recipient statuses:
@@ -68,27 +68,27 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
def test_all_options(self):
send_at = datetime.now() + timedelta(minutes=2)
message = AnymailMessage(
subject="Anymail SendinBlue all-options integration test",
subject="Anymail Brevo all-options integration test",
body="This is the text body",
from_email=formataddr(("Test From, with comma", self.from_email)),
to=["test+to1@anymail.dev", '"Recipient 2, OK?" <test+to2@anymail.dev>'],
cc=["test+cc1@anymail.dev", "Copy 2 <test+cc2@anymail.dev>"],
bcc=["test+bcc1@anymail.dev", "Blind Copy 2 <test+bcc2@anymail.dev>"],
# SendinBlue API v3 only supports single reply-to
# Brevo API v3 only supports single reply-to
reply_to=['"Reply, with comma" <reply@example.com>'],
headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3},
metadata={"meta1": "simple string", "meta2": 2},
send_at=send_at,
tags=["tag 1", "tag 2"],
)
# SendinBlue requires an HTML body:
# Brevo requires an HTML body:
message.attach_alternative("<p>HTML content</p>", "text/html")
message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain")
message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv")
message.send()
# SendinBlue always queues:
# Brevo always queues:
self.assertEqual(message.anymail_status.status, {"queued"})
self.assertRegex(message.anymail_status.message_id, r"\<.+@.+\>")
@@ -118,7 +118,7 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
message.attach("attachment1.txt", "Here is some\ntext", "text/plain")
message.send()
# SendinBlue always queues:
# Brevo always queues:
self.assertEqual(message.anymail_status.status, {"queued"})
recipient_status = message.anymail_status.recipients
self.assertEqual(recipient_status["test+to1@anymail.dev"].status, "queued")
@@ -135,11 +135,11 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
recipient_status["test+to2@anymail.dev"].message_id,
)
@override_settings(ANYMAIL_SENDINBLUE_API_KEY="Hey, that's not an API key!")
@override_settings(ANYMAIL_BREVO_API_KEY="Hey, that's not an API key!")
def test_invalid_api_key(self):
with self.assertRaises(AnymailAPIError) as cm:
self.message.send()
err = cm.exception
self.assertEqual(err.status_code, 401)
# Make sure the exception message includes SendinBlue's response:
# Make sure the exception message includes Brevo's response:
self.assertIn("Key not found", str(err))

View File

@@ -6,16 +6,16 @@ from django.test import tag
from anymail.exceptions import AnymailConfigurationError
from anymail.signals import AnymailTrackingEvent
from anymail.webhooks.sendinblue import SendinBlueTrackingWebhookView
from anymail.webhooks.brevo import BrevoTrackingWebhookView
from .webhook_cases import WebhookBasicAuthTestCase, WebhookTestCase
@tag("sendinblue")
class SendinBlueWebhookSecurityTestCase(WebhookBasicAuthTestCase):
@tag("brevo")
class BrevoWebhookSecurityTestCase(WebhookBasicAuthTestCase):
def call_webhook(self):
return self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps({}),
)
@@ -23,23 +23,22 @@ class SendinBlueWebhookSecurityTestCase(WebhookBasicAuthTestCase):
# Actual tests are in WebhookBasicAuthTestCase
@tag("sendinblue")
class SendinBlueDeliveryTestCase(WebhookTestCase):
# SendinBlue's webhook payload data is partially documented at
# https://help.sendinblue.com/hc/en-us/articles/360007666479,
# but it's not completely up to date.
@tag("brevo")
class BrevoDeliveryTestCase(WebhookTestCase):
# Brevo's webhook payload data is documented at
# https://developers.brevo.com/docs/transactional-webhooks.
# The payloads below were obtained through live testing.
def test_sent_event(self):
raw_event = {
"event": "request",
"email": "recipient@example.com",
"id": 9999999, # this seems to be SendinBlue account id (not an event id)
"id": 9999999, # this seems to be Brevo account id (not an event id)
"message-id": "<201803062010.27287306012@smtp-relay.mailin.fr>",
"subject": "Test subject",
# From a message sent at 2018-03-06 11:10:23-08:00
# (2018-03-06 19:10:23+00:00)...
"date": "2018-03-06 11:10:23", # tz from SendinBlue account's preferences
"date": "2018-03-06 11:10:23", # tz from Brevo account's preferences
"ts": 1520331023, # 2018-03-06 10:10:23 -- what time zone is this?
"ts_event": 1520331023, # unclear if this ever differs from "ts"
"ts_epoch": 1520363423000, # 2018-03-06 19:10:23.000+00:00 -- UTC (msec)
@@ -55,16 +54,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"sending_ip": "333.33.33.33",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertIsInstance(event, AnymailTrackingEvent)
@@ -77,7 +76,7 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
self.assertEqual(
event.message_id, "<201803062010.27287306012@smtp-relay.mailin.fr>"
)
# SendinBlue does not provide a unique event id:
# Brevo does not provide a unique event id:
self.assertIsNone(event.event_id)
self.assertEqual(event.recipient, "recipient@example.com")
self.assertEqual(event.metadata, {"meta": "data"})
@@ -93,16 +92,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"message-id": "<201803011158.9876543210@smtp-relay.mailin.fr>",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertIsInstance(event, AnymailTrackingEvent)
@@ -128,16 +127,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"tag": "header-tag",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "bounced")
@@ -158,16 +157,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"reason": "undefined Unable to find MX of domain no-mx.example.com",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "bounced")
@@ -188,16 +187,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"reason": "blocked : due to blacklist user",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "rejected")
@@ -214,16 +213,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"message-id": "<201803011158.9876543210@smtp-relay.mailin.fr>",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "complained")
@@ -231,7 +230,7 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
def test_invalid_email(self):
# "If a ISP again indicated us that the email is not valid or if we discovered
# that the email is not valid." (unclear whether this error originates with the
# receiving MTA or with SendinBlue pre-send) (haven't observed "invalid_email"
# receiving MTA or with Brevo pre-send) (haven't observed "invalid_email"
# event in actual testing; payload below is a guess)
raw_event = {
"event": "invalid_email",
@@ -241,16 +240,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"reason": "(guessing invalid_email includes a reason)",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "bounced")
@@ -262,7 +261,7 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
def test_deferred_event(self):
# Note: the example below is an actual event capture (with 'example.com'
# substituted for the real receiving domain). It's pretty clearly a bounce, not
# a deferral. It looks like SendinBlue mis-categorizes this SMTP response code.
# a deferral. It looks like Brevo mis-categorizes this SMTP response code.
raw_event = {
"event": "deferred",
"email": "notauser@example.com",
@@ -272,16 +271,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
" address rejected: User unknown in virtual alias table",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "deferred")
@@ -294,7 +293,7 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
)
def test_opened_event(self):
# SendinBlue delivers 'unique_opened' only on the first open, and 'opened'
# Brevo delivers 'unique_opened' only on the first open, and 'opened'
# only on the second or later tracking pixel views. (But they used to deliver
# both on the first open.)
raw_event = {
@@ -304,20 +303,20 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"message-id": "<201803011158.9876543210@smtp-relay.mailin.fr>",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "opened")
self.assertIsNone(event.user_agent) # SendinBlue doesn't report user agent
self.assertIsNone(event.user_agent) # Brevo doesn't report user agent
def test_unique_opened_event(self):
# See note in test_opened_event above
@@ -328,16 +327,16 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"message-id": "<201803011158.9876543210@smtp-relay.mailin.fr>",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "opened")
@@ -351,21 +350,21 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"link": "https://example.com/click/me",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "clicked")
self.assertEqual(event.click_url, "https://example.com/click/me")
self.assertIsNone(event.user_agent) # SendinBlue doesn't report user agent
self.assertIsNone(event.user_agent) # Brevo doesn't report user agent
def test_unsubscribe(self):
# "When a person unsubscribes from the email received."
@@ -378,28 +377,28 @@ class SendinBlueDeliveryTestCase(WebhookTestCase):
"message-id": "<201803011158.9876543210@smtp-relay.mailin.fr>",
}
response = self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data=json.dumps(raw_event),
)
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(
self.tracking_handler,
sender=SendinBlueTrackingWebhookView,
sender=BrevoTrackingWebhookView,
event=ANY,
esp_name="SendinBlue",
esp_name="Brevo",
)
event = kwargs["event"]
self.assertEqual(event.event_type, "unsubscribed")
def test_misconfigured_inbound(self):
errmsg = (
"You seem to have set SendinBlue's *inbound* webhook URL"
" to Anymail's SendinBlue *tracking* webhook URL."
"You seem to have set Brevo's *inbound* webhook URL"
" to Anymail's Brevo *tracking* webhook URL."
)
with self.assertRaisesMessage(AnymailConfigurationError, errmsg):
self.client.post(
"/anymail/sendinblue/tracking/",
"/anymail/brevo/tracking/",
content_type="application/json",
data={"items": []},
)