Reformat code with automated tools

Apply standardized code style
This commit is contained in:
medmunds
2023-02-06 12:27:43 -08:00
committed by Mike Edmunds
parent 40891fcb4a
commit b4e22c63b3
94 changed files with 12936 additions and 7443 deletions

View File

@@ -10,17 +10,21 @@ 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_SENDINBLUE_API_KEY = os.getenv("ANYMAIL_TEST_SENDINBLUE_API_KEY")
ANYMAIL_TEST_SENDINBLUE_DOMAIN = os.getenv("ANYMAIL_TEST_SENDINBLUE_DOMAIN")
@tag('sendinblue', '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")
@override_settings(ANYMAIL_SENDINBLUE_API_KEY=ANYMAIL_TEST_SENDINBLUE_API_KEY,
ANYMAIL_SENDINBLUE_SEND_DEFAULTS=dict(),
EMAIL_BACKEND="anymail.backends.sendinblue.EmailBackend")
@tag("sendinblue", "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",
)
@override_settings(
ANYMAIL_SENDINBLUE_API_KEY=ANYMAIL_TEST_SENDINBLUE_API_KEY,
ANYMAIL_SENDINBLUE_SEND_DEFAULTS=dict(),
EMAIL_BACKEND="anymail.backends.sendinblue.EmailBackend",
)
class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""SendinBlue v3 API integration tests
@@ -36,10 +40,14 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
def setUp(self):
super().setUp()
self.from_email = 'from@%s' % ANYMAIL_TEST_SENDINBLUE_DOMAIN
self.message = AnymailMessage('Anymail SendinBlue integration test', 'Text content',
self.from_email, ['test+to1@anymail.dev'])
self.message.attach_alternative('<p>HTML content</p>', "text/html")
self.from_email = "from@%s" % ANYMAIL_TEST_SENDINBLUE_DOMAIN
self.message = AnymailMessage(
"Anymail SendinBlue integration test",
"Text content",
self.from_email,
["test+to1@anymail.dev"],
)
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
@@ -47,12 +55,14 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
self.assertEqual(sent_count, 1)
anymail_status = self.message.anymail_status
sent_status = anymail_status.recipients['test+to1@anymail.dev'].status
message_id = anymail_status.recipients['test+to1@anymail.dev'].message_id
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.assertRegex(message_id, r'\<.+@.+\>') # Message-ID can be ...@smtp-relay.mail.fr or .sendinblue.com
self.assertEqual(anymail_status.status, {sent_status}) # set of all recipient statuses
self.assertEqual(sent_status, "queued") # SendinBlue always queues
# Message-ID can be ...@smtp-relay.mail.fr or .sendinblue.com:
self.assertRegex(message_id, r"\<.+@.+\>")
# set of all recipient statuses:
self.assertEqual(anymail_status.status, {sent_status})
self.assertEqual(anymail_status.message_id, message_id)
def test_all_options(self):
@@ -64,27 +74,32 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
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>"],
reply_to=['"Reply, with comma" <reply@example.com>'], # SendinBlue API v3 only supports single reply-to
# SendinBlue 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"],
)
message.attach_alternative('<p>HTML content</p>', "text/html") # SendinBlue requires an HTML body
# SendinBlue 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()
self.assertEqual(message.anymail_status.status, {'queued'}) # SendinBlue always queues
self.assertRegex(message.anymail_status.message_id, r'\<.+@.+\>')
# SendinBlue always queues:
self.assertEqual(message.anymail_status.status, {"queued"})
self.assertRegex(message.anymail_status.message_id, r"\<.+@.+\>")
def test_template(self):
message = AnymailMessage(
template_id=5, # There is a *new-style* template with this id in the Anymail test account
from_email=formataddr(('Sender', self.from_email)), # Override template sender
to=["Recipient <test+to1@anymail.dev>"], # No batch send (so max one recipient suggested)
# There is a *new-style* template with this id in the Anymail test account:
template_id=5,
# Override template sender:
from_email=formataddr("Sender", self.from_email),
# No batch send (so max one recipient suggested):
to=["Recipient <test+to1@anymail.dev>"],
reply_to=["Do not reply <reply@example.dev>"],
tags=["using-template"],
headers={"X-Anymail-Test": "group: A, variation: C"},
@@ -98,20 +113,25 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
)
# Normal attachments don't work with Sendinblue templates:
# message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain")
# message.attach("attachment1.txt", "Here is some\ntext", "text/plain")
# If you can host the attachment content on some publicly-accessible URL,
# this *non-portable* alternative allows sending attachments with templates:
message.esp_extra = {
'attachment': [{
'name': 'attachment1.txt',
# URL where Sendinblue can download the attachment content while sending:
'url': 'https://raw.githubusercontent.com/anymail/django-anymail/main/AUTHORS.txt',
}]
"attachment": [
{
"name": "attachment1.txt",
# URL where Sendinblue can download
# the attachment content while sending:
"url": "https://raw.githubusercontent.com/anymail"
"/django-anymail/main/AUTHORS.txt",
}
]
}
message.send()
self.assertEqual(message.anymail_status.status, {'queued'}) # SendinBlue always queues
self.assertRegex(message.anymail_status.message_id, r'\<.+@.+\>')
# SendinBlue always queues:
self.assertEqual(message.anymail_status.status, {"queued"})
self.assertRegex(message.anymail_status.message_id, r"\<.+@.+\>")
@override_settings(ANYMAIL_SENDINBLUE_API_KEY="Hey, that's not an API key!")
def test_invalid_api_key(self):