Move CI testing to GitHub Actions

Related changes:
* remove Travis-CI config; stop running tests on Travis
* rename live integration test environment variables
  to all start with `ANYMAIL_TEST_` (simplifies tox config)
This commit is contained in:
Mike Edmunds
2020-11-28 18:08:01 -08:00
committed by GitHub
parent 8c1749c6f3
commit 5cbaa24002
16 changed files with 181 additions and 152 deletions

View File

@@ -10,13 +10,13 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin, sample_image_path
AMAZON_SES_TEST_ACCESS_KEY_ID = os.getenv("AMAZON_SES_TEST_ACCESS_KEY_ID")
AMAZON_SES_TEST_SECRET_ACCESS_KEY = os.getenv("AMAZON_SES_TEST_SECRET_ACCESS_KEY")
AMAZON_SES_TEST_REGION_NAME = os.getenv("AMAZON_SES_TEST_REGION_NAME", "us-east-1")
ANYMAIL_TEST_AMAZON_SES_ACCESS_KEY_ID = os.getenv("ANYMAIL_TEST_AMAZON_SES_ACCESS_KEY_ID")
ANYMAIL_TEST_AMAZON_SES_SECRET_ACCESS_KEY = os.getenv("ANYMAIL_TEST_AMAZON_SES_SECRET_ACCESS_KEY")
ANYMAIL_TEST_AMAZON_SES_REGION_NAME = os.getenv("ANYMAIL_TEST_AMAZON_SES_REGION_NAME", "us-east-1")
@unittest.skipUnless(AMAZON_SES_TEST_ACCESS_KEY_ID and AMAZON_SES_TEST_SECRET_ACCESS_KEY,
"Set AMAZON_SES_TEST_ACCESS_KEY_ID and AMAZON_SES_TEST_SECRET_ACCESS_KEY "
@unittest.skipUnless(ANYMAIL_TEST_AMAZON_SES_ACCESS_KEY_ID and ANYMAIL_TEST_AMAZON_SES_SECRET_ACCESS_KEY,
"Set ANYMAIL_TEST_AMAZON_SES_ACCESS_KEY_ID and ANYMAIL_TEST_AMAZON_SES_SECRET_ACCESS_KEY "
"environment variables to run Amazon SES integration tests")
@override_settings(
EMAIL_BACKEND="anymail.backends.amazon_ses.EmailBackend",
@@ -25,9 +25,9 @@ AMAZON_SES_TEST_REGION_NAME = os.getenv("AMAZON_SES_TEST_REGION_NAME", "us-east-
# This setting provides Anymail-specific AWS credentials to boto3.client(),
# overriding any credentials in the environment or boto config. It's often
# *not* the best approach -- see the Anymail and boto3 docs for other options.
"aws_access_key_id": AMAZON_SES_TEST_ACCESS_KEY_ID,
"aws_secret_access_key": AMAZON_SES_TEST_SECRET_ACCESS_KEY,
"region_name": AMAZON_SES_TEST_REGION_NAME,
"aws_access_key_id": ANYMAIL_TEST_AMAZON_SES_ACCESS_KEY_ID,
"aws_secret_access_key": ANYMAIL_TEST_AMAZON_SES_SECRET_ACCESS_KEY,
"region_name": ANYMAIL_TEST_AMAZON_SES_REGION_NAME,
# Can supply any other boto3.client params, including botocore.config.Config as dict
"config": {"retries": {"max_attempts": 2}},
},
@@ -38,9 +38,9 @@ class AmazonSESBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""Amazon SES API integration tests
These tests run against the **live** Amazon SES API, using the environment
variables `AMAZON_SES_TEST_ACCESS_KEY_ID` and `AMAZON_SES_TEST_SECRET_ACCESS_KEY`
variables `ANYMAIL_TEST_AMAZON_SES_ACCESS_KEY_ID` and `ANYMAIL_TEST_AMAZON_SES_SECRET_ACCESS_KEY`
as AWS credentials. If those variables are not set, these tests won't run.
(You can also set the environment variable `AMAZON_SES_TEST_REGION_NAME`
(You can also set the environment variable `ANYMAIL_TEST_AMAZON_SES_REGION_NAME`
to test SES using a region other than the default "us-east-1".)
Amazon SES doesn't offer a test mode -- it tries to send everything you ask.
@@ -142,7 +142,7 @@ class AmazonSESBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"AMAZON_SES_CLIENT_PARAMS": {
"aws_access_key_id": "test-invalid-access-key-id",
"aws_secret_access_key": "test-invalid-secret-access-key",
"region_name": AMAZON_SES_TEST_REGION_NAME,
"region_name": ANYMAIL_TEST_AMAZON_SES_REGION_NAME,
}
})
def test_invalid_aws_credentials(self):

View File

@@ -12,24 +12,24 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin, sample_image_path
MAILGUN_TEST_API_KEY = os.getenv('MAILGUN_TEST_API_KEY')
MAILGUN_TEST_DOMAIN = os.getenv('MAILGUN_TEST_DOMAIN')
ANYMAIL_TEST_MAILGUN_API_KEY = os.getenv('ANYMAIL_TEST_MAILGUN_API_KEY')
ANYMAIL_TEST_MAILGUN_DOMAIN = os.getenv('ANYMAIL_TEST_MAILGUN_DOMAIN')
@tag('mailgun', 'live')
@unittest.skipUnless(MAILGUN_TEST_API_KEY and MAILGUN_TEST_DOMAIN,
"Set MAILGUN_TEST_API_KEY and MAILGUN_TEST_DOMAIN environment variables "
@unittest.skipUnless(ANYMAIL_TEST_MAILGUN_API_KEY and ANYMAIL_TEST_MAILGUN_DOMAIN,
"Set ANYMAIL_TEST_MAILGUN_API_KEY and ANYMAIL_TEST_MAILGUN_DOMAIN environment variables "
"to run Mailgun integration tests")
@override_settings(ANYMAIL={'MAILGUN_API_KEY': MAILGUN_TEST_API_KEY,
'MAILGUN_SENDER_DOMAIN': MAILGUN_TEST_DOMAIN,
@override_settings(ANYMAIL={'MAILGUN_API_KEY': ANYMAIL_TEST_MAILGUN_API_KEY,
'MAILGUN_SENDER_DOMAIN': ANYMAIL_TEST_MAILGUN_DOMAIN,
'MAILGUN_SEND_DEFAULTS': {'esp_extra': {'o:testmode': 'yes'}}},
EMAIL_BACKEND="anymail.backends.mailgun.EmailBackend")
class MailgunBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""Mailgun API integration tests
These tests run against the **live** Mailgun API, using the
environment variable `MAILGUN_TEST_API_KEY` as the API key
and `MAILGUN_TEST_DOMAIN` as the sender domain.
environment variable `ANYMAIL_TEST_MAILGUN_API_KEY` as the API key
and `ANYMAIL_TEST_MAILGUN_DOMAIN` as the sender domain.
If those variables are not set, these tests won't run.
"""
@@ -43,8 +43,8 @@ class MailgunBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
def fetch_mailgun_events(self, message_id, event=None,
initial_delay=2, retry_delay=2, max_retries=5):
"""Return list of Mailgun events related to message_id"""
url = "https://api.mailgun.net/v3/%s/events" % MAILGUN_TEST_DOMAIN
auth = ("api", MAILGUN_TEST_API_KEY)
url = "https://api.mailgun.net/v3/%s/events" % ANYMAIL_TEST_MAILGUN_DOMAIN
auth = ("api", ANYMAIL_TEST_MAILGUN_API_KEY)
# Despite the docs, Mailgun's events API actually expects the message-id
# without the <...> brackets (so, not exactly "as returned by the messages API")
@@ -116,7 +116,7 @@ class MailgunBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
)
message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain")
message.attach("vedhæftet fil.csv", "ID,Name\n1,3", "text/csv")
cid = message.attach_inline_image_file(sample_image_path(), domain=MAILGUN_TEST_DOMAIN)
cid = message.attach_inline_image_file(sample_image_path(), domain=ANYMAIL_TEST_MAILGUN_DOMAIN)
message.attach_alternative(
"<div>This is the <i>html</i> body <img src='cid:%s'></div>" % cid,
"text/html")
@@ -195,7 +195,7 @@ class MailgunBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
# self.assertIn("'from' parameter is not a valid address", str(err))
@override_settings(ANYMAIL={'MAILGUN_API_KEY': "Hey, that's not an API key",
'MAILGUN_SENDER_DOMAIN': MAILGUN_TEST_DOMAIN,
'MAILGUN_SENDER_DOMAIN': ANYMAIL_TEST_MAILGUN_DOMAIN,
'MAILGUN_SEND_DEFAULTS': {'esp_extra': {'o:testmode': 'yes'}}})
def test_invalid_api_key(self):
with self.assertRaises(AnymailAPIError) as cm:

View File

@@ -8,16 +8,16 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin, sample_image_path
MAILJET_TEST_API_KEY = os.getenv('MAILJET_TEST_API_KEY')
MAILJET_TEST_SECRET_KEY = os.getenv('MAILJET_TEST_SECRET_KEY')
ANYMAIL_TEST_MAILJET_API_KEY = os.getenv('ANYMAIL_TEST_MAILJET_API_KEY')
ANYMAIL_TEST_MAILJET_SECRET_KEY = os.getenv('ANYMAIL_TEST_MAILJET_SECRET_KEY')
@tag('mailjet', 'live')
@unittest.skipUnless(MAILJET_TEST_API_KEY and MAILJET_TEST_SECRET_KEY,
"Set MAILJET_TEST_API_KEY and MAILJET_TEST_SECRET_KEY "
@unittest.skipUnless(ANYMAIL_TEST_MAILJET_API_KEY and ANYMAIL_TEST_MAILJET_SECRET_KEY,
"Set ANYMAIL_TEST_MAILJET_API_KEY and ANYMAIL_TEST_MAILJET_SECRET_KEY "
"environment variables to run Mailjet integration tests")
@override_settings(ANYMAIL={"MAILJET_API_KEY": MAILJET_TEST_API_KEY,
"MAILJET_SECRET_KEY": MAILJET_TEST_SECRET_KEY,
@override_settings(ANYMAIL={"MAILJET_API_KEY": ANYMAIL_TEST_MAILJET_API_KEY,
"MAILJET_SECRET_KEY": ANYMAIL_TEST_MAILJET_SECRET_KEY,
"MAILJET_SEND_DEFAULTS": {"esp_extra": {"SandboxMode": True}}, # don't actually send mail
},
EMAIL_BACKEND="anymail.backends.mailjet.EmailBackend")
@@ -25,7 +25,7 @@ class MailjetBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""Mailjet API integration tests
These tests run against the **live** Mailjet API, using the
environment variables `MAILJET_TEST_API_KEY` and `MAILJET_TEST_SECRET_KEY`
environment variables `ANYMAIL_TEST_MAILJET_API_KEY` and `ANYMAIL_TEST_MAILJET_SECRET_KEY`
as the API key and API secret key, respectively.
If those variables are not set, these tests won't run.

View File

@@ -9,19 +9,19 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin, sample_image_path
MANDRILL_TEST_API_KEY = os.getenv('MANDRILL_TEST_API_KEY')
ANYMAIL_TEST_MANDRILL_API_KEY = os.getenv('ANYMAIL_TEST_MANDRILL_API_KEY')
@tag('mandrill', 'live')
@unittest.skipUnless(MANDRILL_TEST_API_KEY,
"Set MANDRILL_TEST_API_KEY environment variable to run integration tests")
@override_settings(MANDRILL_API_KEY=MANDRILL_TEST_API_KEY,
@unittest.skipUnless(ANYMAIL_TEST_MANDRILL_API_KEY,
"Set ANYMAIL_TEST_MANDRILL_API_KEY environment variable to run integration tests")
@override_settings(MANDRILL_API_KEY=ANYMAIL_TEST_MANDRILL_API_KEY,
EMAIL_BACKEND="anymail.backends.mandrill.EmailBackend")
class MandrillBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""Mandrill API integration tests
These tests run against the **live** Mandrill API, using the
environment variable `MANDRILL_TEST_API_KEY` as the API key.
environment variable `ANYMAIL_TEST_MANDRILL_API_KEY` as the API key.
If that variable is not set, these tests won't run.
See https://mandrill.zendesk.com/hc/en-us/articles/205582447

View File

@@ -11,8 +11,8 @@ from .utils import AnymailTestMixin, sample_image_path
# For most integration tests, Postmark's sandboxed "POSTMARK_API_TEST" token is used.
# But to test template sends, a real Postmark server token and template id are needed:
POSTMARK_TEST_SERVER_TOKEN = os.getenv('POSTMARK_TEST_SERVER_TOKEN')
POSTMARK_TEST_TEMPLATE_ID = os.getenv('POSTMARK_TEST_TEMPLATE_ID')
ANYMAIL_TEST_POSTMARK_SERVER_TOKEN = os.getenv('ANYMAIL_TEST_POSTMARK_SERVER_TOKEN')
ANYMAIL_TEST_POSTMARK_TEMPLATE_ID = os.getenv('ANYMAIL_TEST_POSTMARK_TEMPLATE_ID')
@tag('postmark', 'live')
@@ -88,15 +88,15 @@ class PostmarkBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
self.assertEqual(err.status_code, 422)
self.assertIn("Invalid 'From' address", str(err))
@unittest.skipUnless(POSTMARK_TEST_SERVER_TOKEN and POSTMARK_TEST_TEMPLATE_ID,
"Set POSTMARK_TEST_SERVER_TOKEN and POSTMARK_TEST_TEMPLATE_ID "
@unittest.skipUnless(ANYMAIL_TEST_POSTMARK_SERVER_TOKEN and ANYMAIL_TEST_POSTMARK_TEMPLATE_ID,
"Set ANYMAIL_TEST_POSTMARK_SERVER_TOKEN and ANYMAIL_TEST_POSTMARK_TEMPLATE_ID "
"environment variables to run Postmark template integration tests")
@override_settings(ANYMAIL_POSTMARK_SERVER_TOKEN=POSTMARK_TEST_SERVER_TOKEN)
@override_settings(ANYMAIL_POSTMARK_SERVER_TOKEN=ANYMAIL_TEST_POSTMARK_SERVER_TOKEN)
def test_template(self):
message = AnymailMessage(
from_email="from@test-pm.anymail.info",
to=["test+to1@anymail.info", "Second Recipient <test+to2@anymail.info>"],
template_id=POSTMARK_TEST_TEMPLATE_ID,
template_id=ANYMAIL_TEST_POSTMARK_TEMPLATE_ID,
merge_data={
"test+to1@anymail.info": {"name": "Recipient 1", "order_no": "12345"},
"test+to2@anymail.info": {"order_no": "6789"},

View File

@@ -9,15 +9,15 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin, sample_image_path
SENDGRID_TEST_API_KEY = os.getenv('SENDGRID_TEST_API_KEY')
SENDGRID_TEST_TEMPLATE_ID = os.getenv('SENDGRID_TEST_TEMPLATE_ID')
ANYMAIL_TEST_SENDGRID_API_KEY = os.getenv('ANYMAIL_TEST_SENDGRID_API_KEY')
ANYMAIL_TEST_SENDGRID_TEMPLATE_ID = os.getenv('ANYMAIL_TEST_SENDGRID_TEMPLATE_ID')
@tag('sendgrid', 'live')
@unittest.skipUnless(SENDGRID_TEST_API_KEY,
"Set SENDGRID_TEST_API_KEY environment variable "
@unittest.skipUnless(ANYMAIL_TEST_SENDGRID_API_KEY,
"Set ANYMAIL_TEST_SENDGRID_API_KEY environment variable "
"to run SendGrid integration tests")
@override_settings(ANYMAIL_SENDGRID_API_KEY=SENDGRID_TEST_API_KEY,
@override_settings(ANYMAIL_SENDGRID_API_KEY=ANYMAIL_TEST_SENDGRID_API_KEY,
ANYMAIL_SENDGRID_SEND_DEFAULTS={"esp_extra": {
"mail_settings": {"sandbox_mode": {"enable": True}},
}},
@@ -26,7 +26,7 @@ class SendGridBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""SendGrid v3 API integration tests
These tests run against the **live** SendGrid API, using the
environment variable `SENDGRID_TEST_API_KEY` as the API key
environment variable `ANYMAIL_TEST_SENDGRID_API_KEY` as the API key
If those variables are not set, these tests won't run.
The SEND_DEFAULTS above force SendGrid's v3 sandbox mode, which avoids sending mail.
@@ -107,15 +107,15 @@ class SendGridBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
self.assertEqual(recipient_status['to1@sink.sendgrid.net'].status, 'queued')
self.assertEqual(recipient_status['to2@sink.sendgrid.net'].status, 'queued')
@unittest.skipUnless(SENDGRID_TEST_TEMPLATE_ID,
"Set the SENDGRID_TEST_TEMPLATE_ID environment variable "
@unittest.skipUnless(ANYMAIL_TEST_SENDGRID_TEMPLATE_ID,
"Set the ANYMAIL_TEST_SENDGRID_TEMPLATE_ID environment variable "
"to a template in your SendGrid account to test stored templates")
def test_stored_template(self):
message = AnymailMessage(
from_email="Test From <from@example.com>",
to=["to@sink.sendgrid.net"],
# Anymail's live test template has merge fields "name", "order_no", and "dept"...
template_id=SENDGRID_TEST_TEMPLATE_ID,
template_id=ANYMAIL_TEST_SENDGRID_TEMPLATE_ID,
merge_data={
'to@sink.sendgrid.net': {
'name': "Test Recipient",

View File

@@ -8,14 +8,14 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin
SENDINBLUE_TEST_API_KEY = os.getenv('SENDINBLUE_TEST_API_KEY')
ANYMAIL_TEST_SENDINBLUE_API_KEY = os.getenv('ANYMAIL_TEST_SENDINBLUE_API_KEY')
@tag('sendinblue', 'live')
@unittest.skipUnless(SENDINBLUE_TEST_API_KEY,
"Set SENDINBLUE_TEST_API_KEY environment variable "
@unittest.skipUnless(ANYMAIL_TEST_SENDINBLUE_API_KEY,
"Set ANYMAIL_TEST_SENDINBLUE_API_KEY environment variable "
"to run SendinBlue integration tests")
@override_settings(ANYMAIL_SENDINBLUE_API_KEY=SENDINBLUE_TEST_API_KEY,
@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):
@@ -23,7 +23,7 @@ class SendinBlueBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
SendinBlue doesn't have sandbox so these tests run
against the **live** SendinBlue API, using the
environment variable `SENDINBLUE_TEST_API_KEY` as the API key
environment variable `ANYMAIL_TEST_SENDINBLUE_API_KEY` as the API key
If those variables are not set, these tests won't run.
https://developers.sendinblue.com/docs/faq#section-how-can-i-test-the-api-

View File

@@ -9,20 +9,20 @@ from anymail.message import AnymailMessage
from .utils import AnymailTestMixin, sample_image_path
SPARKPOST_TEST_API_KEY = os.getenv('SPARKPOST_TEST_API_KEY')
ANYMAIL_TEST_SPARKPOST_API_KEY = os.getenv('ANYMAIL_TEST_SPARKPOST_API_KEY')
@tag('sparkpost', 'live')
@unittest.skipUnless(SPARKPOST_TEST_API_KEY,
"Set SPARKPOST_TEST_API_KEY environment variable "
@unittest.skipUnless(ANYMAIL_TEST_SPARKPOST_API_KEY,
"Set ANYMAIL_TEST_SPARKPOST_API_KEY environment variable "
"to run SparkPost integration tests")
@override_settings(ANYMAIL_SPARKPOST_API_KEY=SPARKPOST_TEST_API_KEY,
@override_settings(ANYMAIL_SPARKPOST_API_KEY=ANYMAIL_TEST_SPARKPOST_API_KEY,
EMAIL_BACKEND="anymail.backends.sparkpost.EmailBackend")
class SparkPostBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
"""SparkPost API integration tests
These tests run against the **live** SparkPost API, using the
environment variable `SPARKPOST_TEST_API_KEY` as the API key
environment variable `ANYMAIL_TEST_SPARKPOST_API_KEY` as the API key
If that variable is not set, these tests won't run.
SparkPost doesn't offer a test mode -- it tries to send everything