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

@@ -1,4 +1,4 @@
from django.test import override_settings, SimpleTestCase, tag
from django.test import SimpleTestCase, override_settings, tag
from anymail.backends.base_requests import AnymailRequestsBackend, RequestsPayload
from anymail.message import AnymailMessage, AnymailRecipientStatus
@@ -21,7 +21,7 @@ class MinimalRequestsBackend(AnymailRequestsBackend):
return MinimalRequestsPayload(message, defaults, self, **_payload_init)
def parse_recipient_status(self, response, payload, message):
return {'to@example.com': AnymailRecipientStatus('message-id', 'sent')}
return {"to@example.com": AnymailRecipientStatus("message-id", "sent")}
class MinimalRequestsPayload(RequestsPayload):
@@ -41,13 +41,15 @@ class MinimalRequestsPayload(RequestsPayload):
add_attachment = _noop
@override_settings(EMAIL_BACKEND='tests.test_base_backends.MinimalRequestsBackend')
@override_settings(EMAIL_BACKEND="tests.test_base_backends.MinimalRequestsBackend")
class RequestsBackendBaseTestCase(RequestsBackendMockAPITestCase):
"""Test common functionality in AnymailRequestsBackend"""
def setUp(self):
super().setUp()
self.message = AnymailMessage('Subject', 'Text Body', 'from@example.com', ['to@example.com'])
self.message = AnymailMessage(
"Subject", "Text Body", "from@example.com", ["to@example.com"]
)
def test_minimal_requests_backend(self):
"""Make sure the testing backend defined above actually works"""
@@ -57,23 +59,25 @@ class RequestsBackendBaseTestCase(RequestsBackendMockAPITestCase):
def test_timeout_default(self):
"""All requests have a 30 second default timeout"""
self.message.send()
timeout = self.get_api_call_arg('timeout')
timeout = self.get_api_call_arg("timeout")
self.assertEqual(timeout, 30)
@override_settings(ANYMAIL_REQUESTS_TIMEOUT=5)
def test_timeout_setting(self):
"""You can use the Anymail setting REQUESTS_TIMEOUT to override the default"""
self.message.send()
timeout = self.get_api_call_arg('timeout')
timeout = self.get_api_call_arg("timeout")
self.assertEqual(timeout, 5)
@tag('live')
@override_settings(EMAIL_BACKEND='tests.test_base_backends.MinimalRequestsBackend')
@tag("live")
@override_settings(EMAIL_BACKEND="tests.test_base_backends.MinimalRequestsBackend")
class RequestsBackendLiveTestCase(AnymailTestMixin, SimpleTestCase):
@override_settings(ANYMAIL_DEBUG_API_REQUESTS=True)
def test_debug_logging(self):
message = AnymailMessage('Subject', 'Text Body', 'from@example.com', ['to@example.com'])
message = AnymailMessage(
"Subject", "Text Body", "from@example.com", ["to@example.com"]
)
message._payload_init = dict(
data="Request body",
headers={
@@ -84,8 +88,9 @@ class RequestsBackendLiveTestCase(AnymailTestMixin, SimpleTestCase):
with self.assertPrints("===== Anymail API request") as outbuf:
message.send()
# Header order and response data vary to much to do a full comparison, but make sure
# that the output contains some expected pieces of the request and the response"
# Header order and response data vary too much to do a full comparison,
# but make sure that the output contains some expected pieces of the request
# and the response
output = outbuf.getvalue()
self.assertIn("\nPOST https://httpbin.org/post\n", output)
self.assertIn("\nUser-Agent: django-anymail/", output)
@@ -98,7 +103,9 @@ class RequestsBackendLiveTestCase(AnymailTestMixin, SimpleTestCase):
def test_no_debug_logging(self):
# Make sure it doesn't output anything when DEBUG_API_REQUESTS is not set
message = AnymailMessage('Subject', 'Text Body', 'from@example.com', ['to@example.com'])
message = AnymailMessage(
"Subject", "Text Body", "from@example.com", ["to@example.com"]
)
message._payload_init = dict(
data="Request body",
headers={