mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Drop Python 2 and Django 1.11 support
Minimum supported versions are now Django 2.0, Python 3.5. This touches a lot of code, to: * Remove obsolete portability code and workarounds (six, backports of email parsers, test utils, etc.) * Use Python 3 syntax (class defs, raise ... from, etc.) * Correct inheritance for mixin classes * Fix outdated docs content and links * Suppress Python 3 "unclosed SSLSocket" ResourceWarnings that are beyond our control (in integration tests due to boto3, python-sparkpost)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import unittest
|
||||
import warnings
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.test import SimpleTestCase, override_settings, tag
|
||||
@@ -18,7 +19,7 @@ SPARKPOST_TEST_API_KEY = os.getenv('SPARKPOST_TEST_API_KEY')
|
||||
"to run SparkPost integration tests")
|
||||
@override_settings(ANYMAIL_SPARKPOST_API_KEY=SPARKPOST_TEST_API_KEY,
|
||||
EMAIL_BACKEND="anymail.backends.sparkpost.EmailBackend")
|
||||
class SparkPostBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
class SparkPostBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
|
||||
"""SparkPost API integration tests
|
||||
|
||||
These tests run against the **live** SparkPost API, using the
|
||||
@@ -28,19 +29,31 @@ class SparkPostBackendIntegrationTests(SimpleTestCase, AnymailTestMixin):
|
||||
SparkPost doesn't offer a test mode -- it tries to send everything
|
||||
you ask. To avoid stacking up a pile of undeliverable @example.com
|
||||
emails, the tests use SparkPost's "sink domain" @*.sink.sparkpostmail.com.
|
||||
https://support.sparkpost.com/customer/en/portal/articles/2361300-how-to-test-integrations
|
||||
https://www.sparkpost.com/docs/faq/using-sink-server/
|
||||
|
||||
SparkPost also doesn't support arbitrary senders (so no from@example.com).
|
||||
We've set up @test-sp.anymail.info as a validated sending domain for these tests.
|
||||
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(SparkPostBackendIntegrationTests, self).setUp()
|
||||
super().setUp()
|
||||
self.message = AnymailMessage('Anymail SparkPost integration test', 'Text content',
|
||||
'test@test-sp.anymail.info', ['to@test.sink.sparkpostmail.com'])
|
||||
self.message.attach_alternative('<p>HTML content</p>', "text/html")
|
||||
|
||||
# The SparkPost Python package uses requests directly, without managing sessions, and relies
|
||||
# on GC to close connections. This leads to harmless (but valid) warnings about unclosed
|
||||
# ssl.SSLSocket during cleanup: https://github.com/psf/requests/issues/1882
|
||||
# There's not much we can do about that, short of switching from the SparkPost package
|
||||
# to our own requests backend implementation (which *does* manage sessions properly).
|
||||
# Unless/until we do that, filter the warnings to avoid test noise.
|
||||
# Filter in TestCase.setUp because unittest resets the warning filters for each test.
|
||||
# https://stackoverflow.com/a/26620811/647002
|
||||
from anymail.backends.base_requests import AnymailRequestsBackend
|
||||
from anymail.backends.sparkpost import EmailBackend as SparkPostBackend
|
||||
assert not issubclass(SparkPostBackend, AnymailRequestsBackend) # else this filter can be removed
|
||||
warnings.filterwarnings("ignore", message=r"unclosed <ssl\.SSLSocket", category=ResourceWarning)
|
||||
|
||||
def test_simple_send(self):
|
||||
# Example of getting the SparkPost send status and transmission id from the message
|
||||
sent_count = self.message.send()
|
||||
|
||||
Reference in New Issue
Block a user