mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Tests: use deliverable recipient addresses for live integration tests
Using undeliverable @example.com recipient addresses leads some ESPs to flag the Anymail test accounts. Switch all live integration tests to mailinator.com recipients (unless they were already using the ESP's own "test sink" addresses).
This commit is contained in:
@@ -37,8 +37,8 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(MailgunBackendIntegrationTests, self).setUp()
|
||||
self.message = AnymailMessage('Anymail integration test', 'Text content',
|
||||
'from@example.com', ['to@example.com'])
|
||||
self.message = AnymailMessage('Anymail Mailgun integration test', 'Text content',
|
||||
'from@example.com', ['anymail-test-to1@mailinator.com'])
|
||||
self.message.attach_alternative('<p>HTML content</p>', "text/html")
|
||||
|
||||
def fetch_mailgun_events(self, message_id, event=None,
|
||||
@@ -87,8 +87,8 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
self.assertEqual(sent_count, 1)
|
||||
|
||||
anymail_status = self.message.anymail_status
|
||||
sent_status = anymail_status.recipients['to@example.com'].status
|
||||
message_id = anymail_status.recipients['to@example.com'].message_id
|
||||
sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
|
||||
message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
|
||||
|
||||
self.assertEqual(sent_status, 'queued') # Mailgun always queues
|
||||
self.assertGreater(len(message_id), 0) # don't know what it'll be, but it should exist
|
||||
@@ -100,12 +100,12 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
send_at = datetime.now().replace(microsecond=0) + timedelta(minutes=2)
|
||||
send_at_timestamp = mktime(send_at.timetuple()) # python3: send_at.timestamp()
|
||||
message = AnymailMessage(
|
||||
subject="Anymail all-options integration test",
|
||||
subject="Anymail Mailgun all-options integration test",
|
||||
body="This is the text body",
|
||||
from_email="Test From <from@example.com>, also-from@example.com",
|
||||
to=["to1@example.com", "Recipient 2 <to2@example.com>"],
|
||||
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"],
|
||||
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.com>"],
|
||||
to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
|
||||
cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
|
||||
bcc=["anymail-test-bcc1@mailinator.com", "Blind Copy 2 <anymail-test-bcc2@mailinator.com>"],
|
||||
reply_to=["reply1@example.com", "Reply 2 <reply2@example.com>"],
|
||||
headers={"X-Anymail-Test": "value"},
|
||||
|
||||
@@ -137,13 +137,15 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
{"meta1": "simple string", "meta2": "2"}) # all metadata values become strings
|
||||
|
||||
self.assertEqual(event["message"]["scheduled-for"], send_at_timestamp)
|
||||
self.assertIn(event["recipient"], ['to1@example.com', 'to2@example.com', 'cc1@example.com',
|
||||
'cc2@example.com', 'bcc1@example.com', 'bcc2@example.com'])
|
||||
self.assertIn(event["recipient"], ['anymail-test-to1@mailinator.com', 'anymail-test-to2@mailinator.com',
|
||||
'anymail-test-cc1@mailinator.com', 'anymail-test-cc1@mailinator.com',
|
||||
'anymail-test-bcc1@mailinator.com', 'anymail-test-bcc2@mailinator.com'])
|
||||
|
||||
headers = event["message"]["headers"]
|
||||
self.assertEqual(headers["from"], "Test From <from@example.com>, also-from@example.com")
|
||||
self.assertEqual(headers["to"], "to1@example.com, Recipient 2 <to2@example.com>")
|
||||
self.assertEqual(headers["subject"], "Anymail all-options integration test")
|
||||
self.assertEqual(headers["to"],
|
||||
"anymail-test-to1@mailinator.com, Recipient 2 <anymail-test-to2@mailinator.com>")
|
||||
self.assertEqual(headers["subject"], "Anymail Mailgun all-options integration test")
|
||||
|
||||
attachments = event["message"]["attachments"]
|
||||
self.assertEqual(len(attachments), 2) # because inline image shouldn't be an attachment
|
||||
|
||||
@@ -39,7 +39,7 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
def setUp(self):
|
||||
super(MailjetBackendIntegrationTests, self).setUp()
|
||||
self.message = AnymailMessage('Anymail Mailjet integration test', 'Text content',
|
||||
'test@test-mj.anymail.info', ['to@example.com'])
|
||||
'test@test-mj.anymail.info', ['anymail-test-to1@mailinator.com'])
|
||||
self.message.attach_alternative('<p>HTML content</p>', "text/html")
|
||||
|
||||
def test_simple_send(self):
|
||||
@@ -48,8 +48,8 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
self.assertEqual(sent_count, 1)
|
||||
|
||||
anymail_status = self.message.anymail_status
|
||||
sent_status = anymail_status.recipients['to@example.com'].status
|
||||
message_id = anymail_status.recipients['to@example.com'].message_id
|
||||
sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
|
||||
message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
|
||||
|
||||
self.assertEqual(sent_status, 'sent')
|
||||
self.assertRegex(message_id, r'.+')
|
||||
@@ -58,12 +58,12 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
def test_all_options(self):
|
||||
message = AnymailMessage(
|
||||
subject="Anymail all-options integration test",
|
||||
subject="Anymail Mailjet all-options integration test",
|
||||
body="This is the text body",
|
||||
from_email='"Test Sender, Inc." <test@test-mj.anymail.info>',
|
||||
to=['to1@example.com', '"Recipient, 2nd" <to2@example.com>'],
|
||||
cc=['cc1@example.com', 'Copy 2 <cc2@example.com>'],
|
||||
bcc=['bcc1@example.com', 'Blind Copy 2 <bcc2@example.com>'],
|
||||
to=['anymail-test-to1@mailinator.com', '"Recipient, 2nd" <anymail-test-to2@mailinator.com>'],
|
||||
cc=['anymail-test-cc1@mailinator.com', 'Copy 2 <anymail-test-cc1@mailinator.com>'],
|
||||
bcc=['anymail-test-bcc1@mailinator.com', 'Blind Copy 2 <anymail-test-bcc2@mailinator.com>'],
|
||||
reply_to=['reply1@example.com', '"Reply, 2nd" <reply2@example.com>'],
|
||||
headers={"X-Anymail-Test": "value"},
|
||||
|
||||
@@ -85,14 +85,14 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
def test_merge_data(self):
|
||||
message = AnymailMessage(
|
||||
subject="Anymail merge_data test", # Mailjet doesn't support merge fields in the subject
|
||||
subject="Anymail Mailjet merge_data test", # Mailjet doesn't support merge fields in the subject
|
||||
body="This body includes merge data: [[var:value]]\n"
|
||||
"And global merge data: [[var:global]]",
|
||||
from_email="Test From <test@test-mj.anymail.info>",
|
||||
to=["to1@example.com", "Recipient 2 <to2@example.com>"],
|
||||
to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
|
||||
merge_data={
|
||||
'to1@example.com': {'value': 'one'},
|
||||
'to2@example.com': {'value': 'two'},
|
||||
'anymail-test-to1@mailinator.com': {'value': 'one'},
|
||||
'anymail-test-to2@mailinator.com': {'value': 'two'},
|
||||
},
|
||||
merge_global_data={
|
||||
'global': 'global_value'
|
||||
@@ -100,15 +100,15 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
)
|
||||
message.send()
|
||||
recipient_status = message.anymail_status.recipients
|
||||
self.assertEqual(recipient_status['to1@example.com'].status, 'sent')
|
||||
self.assertEqual(recipient_status['to2@example.com'].status, 'sent')
|
||||
self.assertEqual(recipient_status['anymail-test-to1@mailinator.com'].status, 'sent')
|
||||
self.assertEqual(recipient_status['anymail-test-to2@mailinator.com'].status, 'sent')
|
||||
|
||||
def test_stored_template(self):
|
||||
message = AnymailMessage(
|
||||
template_id='176375', # ID of the real template named 'test-template' in our Mailjet test account
|
||||
to=["to1@example.com"],
|
||||
to=["anymail-test-to1@mailinator.com"],
|
||||
merge_data={
|
||||
'to1@example.com': {
|
||||
'anymail-test-to1@mailinator.com': {
|
||||
'name': "Test Recipient",
|
||||
}
|
||||
},
|
||||
@@ -119,7 +119,7 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
message.from_email = None # use the template's sender email/name
|
||||
message.send()
|
||||
recipient_status = message.anymail_status.recipients
|
||||
self.assertEqual(recipient_status['to1@example.com'].status, 'sent')
|
||||
self.assertEqual(recipient_status['anymail-test-to1@mailinator.com'].status, 'sent')
|
||||
|
||||
@override_settings(ANYMAIL_MAILJET_API_KEY="Hey, that's not an API key!")
|
||||
def test_invalid_api_key(self):
|
||||
|
||||
@@ -33,7 +33,7 @@ class MandrillBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
def setUp(self):
|
||||
super(MandrillBackendIntegrationTests, self).setUp()
|
||||
self.message = mail.EmailMultiAlternatives('Anymail Mandrill integration test', 'Text content',
|
||||
'from@example.com', ['to@example.com'])
|
||||
'from@example.com', ['anymail-test-to1@mailinator.com'])
|
||||
self.message.attach_alternative('<p>HTML content</p>', "text/html")
|
||||
|
||||
def test_simple_send(self):
|
||||
@@ -43,8 +43,8 @@ class MandrillBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
anymail_status = self.message.anymail_status
|
||||
sent_status = anymail_status.recipients['to@example.com'].status
|
||||
message_id = anymail_status.recipients['to@example.com'].message_id
|
||||
sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
|
||||
message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
|
||||
|
||||
self.assertIn(sent_status, ['sent', 'queued']) # successful send (could still bounce later)
|
||||
self.assertGreater(len(message_id), 0) # don't know what it'll be, but it should exist
|
||||
@@ -54,12 +54,12 @@ class MandrillBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
def test_all_options(self):
|
||||
message = AnymailMessage(
|
||||
subject="Anymail all-options integration test",
|
||||
subject="Anymail Mandrill all-options integration test",
|
||||
body="This is the text body",
|
||||
from_email="Test From <from@example.com>",
|
||||
to=["to1@example.com", "Recipient 2 <to2@example.com>"],
|
||||
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"],
|
||||
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.com>"],
|
||||
to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
|
||||
cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
|
||||
bcc=["anymail-test-bcc1@mailinator.com", "Blind Copy 2 <anymail-test-bcc2@mailinator.com>"],
|
||||
reply_to=["reply1@example.com", "Reply 2 <reply2@example.com>"],
|
||||
headers={"X-Anymail-Test": "value"},
|
||||
|
||||
|
||||
@@ -22,17 +22,17 @@ class PostmarkBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
def setUp(self):
|
||||
super(PostmarkBackendIntegrationTests, self).setUp()
|
||||
self.message = AnymailMessage('Anymail Postmark integration test', 'Text content',
|
||||
'from@example.com', ['to@example.com'])
|
||||
'from@example.com', ['anymail-test-to1@mailinator.com'])
|
||||
self.message.attach_alternative('<p>HTML content</p>', "text/html")
|
||||
|
||||
def test_simple_send(self):
|
||||
# Example of getting the SendGrid send status and message id from the message
|
||||
# Example of getting the Postmark send status and message id from the message
|
||||
sent_count = self.message.send()
|
||||
self.assertEqual(sent_count, 1)
|
||||
|
||||
anymail_status = self.message.anymail_status
|
||||
sent_status = anymail_status.recipients['to@example.com'].status
|
||||
message_id = anymail_status.recipients['to@example.com'].message_id
|
||||
sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
|
||||
message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
|
||||
|
||||
self.assertEqual(sent_status, 'sent')
|
||||
self.assertGreater(len(message_id), 0) # non-empty string
|
||||
@@ -41,13 +41,13 @@ class PostmarkBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
def test_all_options(self):
|
||||
message = AnymailMessage(
|
||||
subject="Anymail all-options integration test",
|
||||
subject="Anymail Postmark all-options integration test",
|
||||
body="This is the text body",
|
||||
# Postmark accepts multiple from_email addresses, but truncates to the first on their end
|
||||
from_email="Test From <from@example.com>, also-from@example.com",
|
||||
to=["to1@example.com", "Recipient 2 <to2@example.com>"],
|
||||
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"],
|
||||
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.com>"],
|
||||
to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
|
||||
cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
|
||||
bcc=["anymail-test-bcc1@mailinator.com", "Blind Copy 2 <anymail-test-bcc2@mailinator.com>"],
|
||||
reply_to=["reply1@example.com", "Reply 2 <reply2@example.com>"],
|
||||
headers={"X-Anymail-Test": "value"},
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
super(SendinBlueBackendIntegrationTests, self).setUp()
|
||||
|
||||
self.message = AnymailMessage('Anymail SendinBlue integration test', 'Text content',
|
||||
'from@example.com', ['to@example.com'])
|
||||
'from@test-sb.anymail.info', ['anymail-test-to1@mailinator.com'])
|
||||
self.message.attach_alternative('<p>HTML content</p>', "text/html")
|
||||
|
||||
def test_simple_send(self):
|
||||
@@ -44,8 +44,8 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
self.assertEqual(sent_count, 1)
|
||||
|
||||
anymail_status = self.message.anymail_status
|
||||
sent_status = anymail_status.recipients['to@example.com'].status
|
||||
message_id = anymail_status.recipients['to@example.com'].message_id
|
||||
sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
|
||||
message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
|
||||
|
||||
self.assertEqual(sent_status, 'queued') # SendinBlue always queues
|
||||
self.assertRegex(message_id, r'\<.+@.+\>') # Message-ID can be ...@smtp-relay.mail.fr or .sendinblue.com
|
||||
@@ -54,12 +54,12 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
|
||||
def test_all_options(self):
|
||||
message = AnymailMessage(
|
||||
subject="Anymail all-options integration test",
|
||||
subject="Anymail SendinBlue all-options integration test",
|
||||
body="This is the text body",
|
||||
from_email='"Test From, with comma" <from@example.com>',
|
||||
to=["to1@example.com", '"Recipient 2, OK?" <to2@example.com>'],
|
||||
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"],
|
||||
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.com>"],
|
||||
from_email='"Test From, with comma" <from@test-sb.anymail.info>',
|
||||
to=["anymail-test-to1@mailinator.com", '"Recipient 2, OK?" <anymail-test-to2@mailinator.com>'],
|
||||
cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
|
||||
bcc=["anymail-test-bcc1@mailinator.com", "Blind Copy 2 <anymail-test-bcc2@mailinator.com>"],
|
||||
reply_to=['"Reply, with comma" <reply@example.com>'], # SendinBlue API v3 only supports single reply-to
|
||||
headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3},
|
||||
|
||||
@@ -78,7 +78,7 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
def test_template(self):
|
||||
message = AnymailMessage(
|
||||
template_id=1, # There is a template with this id in the Anymail test account
|
||||
to=["to1@example.com"], # SendinBlue doesn't allow recipient display names with templates
|
||||
to=["anymail-test-to1@mailinator.com"], # SendinBlue doesn't allow recipient display names with templates
|
||||
reply_to=["reply@example.com"],
|
||||
tags=["using-template"],
|
||||
headers={"X-Anymail-Test": "group: A, variation: C"},
|
||||
|
||||
Reference in New Issue
Block a user