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:
medmunds
2018-03-13 09:08:36 -07:00
parent 70f5e3e84c
commit 3874525fd0
5 changed files with 54 additions and 52 deletions

View File

@@ -37,8 +37,8 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def setUp(self): def setUp(self):
super(MailgunBackendIntegrationTests, self).setUp() super(MailgunBackendIntegrationTests, self).setUp()
self.message = AnymailMessage('Anymail integration test', 'Text content', self.message = AnymailMessage('Anymail Mailgun 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") self.message.attach_alternative('<p>HTML content</p>', "text/html")
def fetch_mailgun_events(self, message_id, event=None, def fetch_mailgun_events(self, message_id, event=None,
@@ -87,8 +87,8 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
self.assertEqual(sent_count, 1) self.assertEqual(sent_count, 1)
anymail_status = self.message.anymail_status anymail_status = self.message.anymail_status
sent_status = anymail_status.recipients['to@example.com'].status sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
message_id = anymail_status.recipients['to@example.com'].message_id message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
self.assertEqual(sent_status, 'queued') # Mailgun always queues 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 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 = datetime.now().replace(microsecond=0) + timedelta(minutes=2)
send_at_timestamp = mktime(send_at.timetuple()) # python3: send_at.timestamp() send_at_timestamp = mktime(send_at.timetuple()) # python3: send_at.timestamp()
message = AnymailMessage( message = AnymailMessage(
subject="Anymail all-options integration test", subject="Anymail Mailgun all-options integration test",
body="This is the text body", body="This is the text body",
from_email="Test From <from@example.com>, also-from@example.com", from_email="Test From <from@example.com>, also-from@example.com",
to=["to1@example.com", "Recipient 2 <to2@example.com>"], to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"], cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.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>"], reply_to=["reply1@example.com", "Reply 2 <reply2@example.com>"],
headers={"X-Anymail-Test": "value"}, headers={"X-Anymail-Test": "value"},
@@ -137,13 +137,15 @@ class MailgunBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
{"meta1": "simple string", "meta2": "2"}) # all metadata values become strings {"meta1": "simple string", "meta2": "2"}) # all metadata values become strings
self.assertEqual(event["message"]["scheduled-for"], send_at_timestamp) self.assertEqual(event["message"]["scheduled-for"], send_at_timestamp)
self.assertIn(event["recipient"], ['to1@example.com', 'to2@example.com', 'cc1@example.com', self.assertIn(event["recipient"], ['anymail-test-to1@mailinator.com', 'anymail-test-to2@mailinator.com',
'cc2@example.com', 'bcc1@example.com', 'bcc2@example.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"] headers = event["message"]["headers"]
self.assertEqual(headers["from"], "Test From <from@example.com>, also-from@example.com") 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["to"],
self.assertEqual(headers["subject"], "Anymail all-options integration test") "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"] attachments = event["message"]["attachments"]
self.assertEqual(len(attachments), 2) # because inline image shouldn't be an attachment self.assertEqual(len(attachments), 2) # because inline image shouldn't be an attachment

View File

@@ -39,7 +39,7 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def setUp(self): def setUp(self):
super(MailjetBackendIntegrationTests, self).setUp() super(MailjetBackendIntegrationTests, self).setUp()
self.message = AnymailMessage('Anymail Mailjet integration test', 'Text content', 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") self.message.attach_alternative('<p>HTML content</p>', "text/html")
def test_simple_send(self): def test_simple_send(self):
@@ -48,8 +48,8 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
self.assertEqual(sent_count, 1) self.assertEqual(sent_count, 1)
anymail_status = self.message.anymail_status anymail_status = self.message.anymail_status
sent_status = anymail_status.recipients['to@example.com'].status sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
message_id = anymail_status.recipients['to@example.com'].message_id message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
self.assertEqual(sent_status, 'sent') self.assertEqual(sent_status, 'sent')
self.assertRegex(message_id, r'.+') self.assertRegex(message_id, r'.+')
@@ -58,12 +58,12 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def test_all_options(self): def test_all_options(self):
message = AnymailMessage( message = AnymailMessage(
subject="Anymail all-options integration test", subject="Anymail Mailjet all-options integration test",
body="This is the text body", body="This is the text body",
from_email='"Test Sender, Inc." <test@test-mj.anymail.info>', from_email='"Test Sender, Inc." <test@test-mj.anymail.info>',
to=['to1@example.com', '"Recipient, 2nd" <to2@example.com>'], to=['anymail-test-to1@mailinator.com', '"Recipient, 2nd" <anymail-test-to2@mailinator.com>'],
cc=['cc1@example.com', 'Copy 2 <cc2@example.com>'], cc=['anymail-test-cc1@mailinator.com', 'Copy 2 <anymail-test-cc1@mailinator.com>'],
bcc=['bcc1@example.com', 'Blind Copy 2 <bcc2@example.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>'], reply_to=['reply1@example.com', '"Reply, 2nd" <reply2@example.com>'],
headers={"X-Anymail-Test": "value"}, headers={"X-Anymail-Test": "value"},
@@ -85,14 +85,14 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def test_merge_data(self): def test_merge_data(self):
message = AnymailMessage( 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" body="This body includes merge data: [[var:value]]\n"
"And global merge data: [[var:global]]", "And global merge data: [[var:global]]",
from_email="Test From <test@test-mj.anymail.info>", 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={ merge_data={
'to1@example.com': {'value': 'one'}, 'anymail-test-to1@mailinator.com': {'value': 'one'},
'to2@example.com': {'value': 'two'}, 'anymail-test-to2@mailinator.com': {'value': 'two'},
}, },
merge_global_data={ merge_global_data={
'global': 'global_value' 'global': 'global_value'
@@ -100,15 +100,15 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
) )
message.send() message.send()
recipient_status = message.anymail_status.recipients 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')
self.assertEqual(recipient_status['to2@example.com'].status, 'sent') self.assertEqual(recipient_status['anymail-test-to2@mailinator.com'].status, 'sent')
def test_stored_template(self): def test_stored_template(self):
message = AnymailMessage( message = AnymailMessage(
template_id='176375', # ID of the real template named 'test-template' in our Mailjet test account 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={ merge_data={
'to1@example.com': { 'anymail-test-to1@mailinator.com': {
'name': "Test Recipient", 'name': "Test Recipient",
} }
}, },
@@ -119,7 +119,7 @@ class MailjetBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
message.from_email = None # use the template's sender email/name message.from_email = None # use the template's sender email/name
message.send() message.send()
recipient_status = message.anymail_status.recipients 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!") @override_settings(ANYMAIL_MAILJET_API_KEY="Hey, that's not an API key!")
def test_invalid_api_key(self): def test_invalid_api_key(self):

View File

@@ -33,7 +33,7 @@ class MandrillBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def setUp(self): def setUp(self):
super(MandrillBackendIntegrationTests, self).setUp() super(MandrillBackendIntegrationTests, self).setUp()
self.message = mail.EmailMultiAlternatives('Anymail Mandrill integration test', 'Text content', 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") self.message.attach_alternative('<p>HTML content</p>', "text/html")
def test_simple_send(self): def test_simple_send(self):
@@ -43,8 +43,8 @@ class MandrillBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
anymail_status = self.message.anymail_status anymail_status = self.message.anymail_status
sent_status = anymail_status.recipients['to@example.com'].status sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
message_id = anymail_status.recipients['to@example.com'].message_id 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.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 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): def test_all_options(self):
message = AnymailMessage( message = AnymailMessage(
subject="Anymail all-options integration test", subject="Anymail Mandrill all-options integration test",
body="This is the text body", body="This is the text body",
from_email="Test From <from@example.com>", from_email="Test From <from@example.com>",
to=["to1@example.com", "Recipient 2 <to2@example.com>"], to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"], cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.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>"], reply_to=["reply1@example.com", "Reply 2 <reply2@example.com>"],
headers={"X-Anymail-Test": "value"}, headers={"X-Anymail-Test": "value"},

View File

@@ -22,17 +22,17 @@ class PostmarkBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def setUp(self): def setUp(self):
super(PostmarkBackendIntegrationTests, self).setUp() super(PostmarkBackendIntegrationTests, self).setUp()
self.message = AnymailMessage('Anymail Postmark integration test', 'Text content', 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") self.message.attach_alternative('<p>HTML content</p>', "text/html")
def test_simple_send(self): 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() sent_count = self.message.send()
self.assertEqual(sent_count, 1) self.assertEqual(sent_count, 1)
anymail_status = self.message.anymail_status anymail_status = self.message.anymail_status
sent_status = anymail_status.recipients['to@example.com'].status sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
message_id = anymail_status.recipients['to@example.com'].message_id message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
self.assertEqual(sent_status, 'sent') self.assertEqual(sent_status, 'sent')
self.assertGreater(len(message_id), 0) # non-empty string self.assertGreater(len(message_id), 0) # non-empty string
@@ -41,13 +41,13 @@ class PostmarkBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def test_all_options(self): def test_all_options(self):
message = AnymailMessage( message = AnymailMessage(
subject="Anymail all-options integration test", subject="Anymail Postmark all-options integration test",
body="This is the text body", body="This is the text body",
# Postmark accepts multiple from_email addresses, but truncates to the first on their end # 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", from_email="Test From <from@example.com>, also-from@example.com",
to=["to1@example.com", "Recipient 2 <to2@example.com>"], to=["anymail-test-to1@mailinator.com", "Recipient 2 <anymail-test-to2@mailinator.com>"],
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"], cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.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>"], reply_to=["reply1@example.com", "Reply 2 <reply2@example.com>"],
headers={"X-Anymail-Test": "value"}, headers={"X-Anymail-Test": "value"},

View File

@@ -35,7 +35,7 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
super(SendinBlueBackendIntegrationTests, self).setUp() super(SendinBlueBackendIntegrationTests, self).setUp()
self.message = AnymailMessage('Anymail SendinBlue integration test', 'Text content', 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") self.message.attach_alternative('<p>HTML content</p>', "text/html")
def test_simple_send(self): def test_simple_send(self):
@@ -44,8 +44,8 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
self.assertEqual(sent_count, 1) self.assertEqual(sent_count, 1)
anymail_status = self.message.anymail_status anymail_status = self.message.anymail_status
sent_status = anymail_status.recipients['to@example.com'].status sent_status = anymail_status.recipients['anymail-test-to1@mailinator.com'].status
message_id = anymail_status.recipients['to@example.com'].message_id message_id = anymail_status.recipients['anymail-test-to1@mailinator.com'].message_id
self.assertEqual(sent_status, 'queued') # SendinBlue always queues self.assertEqual(sent_status, 'queued') # SendinBlue always queues
self.assertRegex(message_id, r'\<.+@.+\>') # Message-ID can be ...@smtp-relay.mail.fr or .sendinblue.com 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): def test_all_options(self):
message = AnymailMessage( message = AnymailMessage(
subject="Anymail all-options integration test", subject="Anymail SendinBlue all-options integration test",
body="This is the text body", body="This is the text body",
from_email='"Test From, with comma" <from@example.com>', from_email='"Test From, with comma" <from@test-sb.anymail.info>',
to=["to1@example.com", '"Recipient 2, OK?" <to2@example.com>'], to=["anymail-test-to1@mailinator.com", '"Recipient 2, OK?" <anymail-test-to2@mailinator.com>'],
cc=["cc1@example.com", "Copy 2 <cc2@example.com>"], cc=["anymail-test-cc1@mailinator.com", "Copy 2 <anymail-test-cc2@mailinator.com>"],
bcc=["bcc1@example.com", "Blind Copy 2 <bcc2@example.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 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}, headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3},
@@ -78,7 +78,7 @@ class SendinBlueBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
def test_template(self): def test_template(self):
message = AnymailMessage( message = AnymailMessage(
template_id=1, # There is a template with this id in the Anymail test account 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"], reply_to=["reply@example.com"],
tags=["using-template"], tags=["using-template"],
headers={"X-Anymail-Test": "group: A, variation: C"}, headers={"X-Anymail-Test": "group: A, variation: C"},