From adc92f037b691d77a0725b96f75ef5ff34983a67 Mon Sep 17 00:00:00 2001 From: Mike Edmunds Date: Sun, 13 Jun 2021 12:13:31 -0700 Subject: [PATCH] Tests: tox and mock cleanup * Remove mock dependency (mock is now part of standard unittest package) * Cleanup tox dependency installation logic --- setup.py | 5 ++++- tests/mock_requests_backend.py | 2 +- tests/test_amazon_ses_backend.py | 2 +- tests/test_amazon_ses_inbound.py | 2 +- tests/test_amazon_ses_webhooks.py | 2 +- tests/test_mailgun_inbound.py | 2 +- tests/test_mailgun_webhooks.py | 2 +- tests/test_mailjet_inbound.py | 2 +- tests/test_mailjet_webhooks.py | 2 +- tests/test_mandrill_inbound.py | 2 +- tests/test_mandrill_webhooks.py | 2 +- tests/test_message.py | 3 ++- tests/test_postal_inbound.py | 2 +- tests/test_postal_webhooks.py | 2 +- tests/test_postmark_inbound.py | 2 +- tests/test_postmark_webhooks.py | 2 +- tests/test_sendgrid_backend.py | 2 +- tests/test_sendgrid_inbound.py | 2 +- tests/test_sendgrid_webhooks.py | 2 +- tests/test_sendinblue_webhooks.py | 2 +- tests/test_sparkpost_inbound.py | 2 +- tests/test_sparkpost_webhooks.py | 2 +- tests/webhook_cases.py | 2 +- tox.ini | 9 +++++---- 24 files changed, 32 insertions(+), 27 deletions(-) diff --git a/setup.py b/setup.py index aa5366e..0395f72 100644 --- a/setup.py +++ b/setup.py @@ -30,15 +30,18 @@ with open(path.join(here, 'README.rst'), encoding='utf-8') as f: long_description = long_description_from_readme(f.read()) +# Additional requirements for development/build/release requirements_dev = [ "flake8", "sphinx", "sphinx-rtd-theme", "tox", "twine", + "wheel", ] -requirements_test = ["mock", "boto3", "cryptography"] +# Additional requirements for running tests +requirements_test = [] setup( diff --git a/tests/mock_requests_backend.py b/tests/mock_requests_backend.py index 750da98..1a050df 100644 --- a/tests/mock_requests_backend.py +++ b/tests/mock_requests_backend.py @@ -1,10 +1,10 @@ import json from io import BytesIO +from unittest.mock import patch from django.core import mail from django.test import SimpleTestCase import requests -from mock import patch from anymail.exceptions import AnymailAPIError diff --git a/tests/test_amazon_ses_backend.py b/tests/test_amazon_ses_backend.py index 9adecb4..ab60c20 100644 --- a/tests/test_amazon_ses_backend.py +++ b/tests/test_amazon_ses_backend.py @@ -1,11 +1,11 @@ import json from datetime import datetime from email.mime.application import MIMEApplication +from unittest.mock import ANY, patch from django.core import mail from django.core.mail import BadHeaderError from django.test import SimpleTestCase, override_settings, tag -from mock import ANY, patch from anymail.exceptions import AnymailAPIError, AnymailUnsupportedFeature from anymail.inbound import AnymailInboundMessage diff --git a/tests/test_amazon_ses_inbound.py b/tests/test_amazon_ses_inbound.py index c115a27..64d37c9 100644 --- a/tests/test_amazon_ses_inbound.py +++ b/tests/test_amazon_ses_inbound.py @@ -2,10 +2,10 @@ import json from base64 import b64encode from datetime import datetime from textwrap import dedent +from unittest.mock import ANY, patch from django.test import tag from django.utils.timezone import utc -from mock import ANY, patch from anymail.exceptions import AnymailAPIError, AnymailConfigurationError from anymail.inbound import AnymailInboundMessage diff --git a/tests/test_amazon_ses_webhooks.py b/tests/test_amazon_ses_webhooks.py index d0eb5f9..467c434 100644 --- a/tests/test_amazon_ses_webhooks.py +++ b/tests/test_amazon_ses_webhooks.py @@ -1,10 +1,10 @@ import json import warnings from datetime import datetime +from unittest.mock import ANY, patch from django.test import SimpleTestCase, override_settings, tag from django.utils.timezone import utc -from mock import ANY, patch from anymail.exceptions import AnymailConfigurationError, AnymailInsecureWebhookWarning from anymail.signals import AnymailTrackingEvent diff --git a/tests/test_mailgun_inbound.py b/tests/test_mailgun_inbound.py index 39c2243..dfc2b92 100644 --- a/tests/test_mailgun_inbound.py +++ b/tests/test_mailgun_inbound.py @@ -2,10 +2,10 @@ import json from datetime import datetime from io import BytesIO from textwrap import dedent +from unittest.mock import ANY from django.test import override_settings, tag from django.utils.timezone import utc -from mock import ANY from anymail.exceptions import AnymailConfigurationError from anymail.inbound import AnymailInboundMessage diff --git a/tests/test_mailgun_webhooks.py b/tests/test_mailgun_webhooks.py index 7ef3809..663a788 100644 --- a/tests/test_mailgun_webhooks.py +++ b/tests/test_mailgun_webhooks.py @@ -1,12 +1,12 @@ import json from datetime import datetime +from unittest.mock import ANY import hashlib import hmac from django.core.exceptions import ImproperlyConfigured from django.test import override_settings, tag from django.utils.timezone import utc -from mock import ANY from anymail.exceptions import AnymailConfigurationError from anymail.signals import AnymailTrackingEvent diff --git a/tests/test_mailjet_inbound.py b/tests/test_mailjet_inbound.py index 84dcef9..7a583ae 100644 --- a/tests/test_mailjet_inbound.py +++ b/tests/test_mailjet_inbound.py @@ -1,8 +1,8 @@ import json from base64 import b64encode +from unittest.mock import ANY from django.test import tag -from mock import ANY from anymail.inbound import AnymailInboundMessage from anymail.signals import AnymailInboundEvent diff --git a/tests/test_mailjet_webhooks.py b/tests/test_mailjet_webhooks.py index f5c9e2b..4594e5e 100644 --- a/tests/test_mailjet_webhooks.py +++ b/tests/test_mailjet_webhooks.py @@ -1,9 +1,9 @@ import json from datetime import datetime +from unittest.mock import ANY from django.test import tag from django.utils.timezone import utc -from mock import ANY from anymail.signals import AnymailTrackingEvent from anymail.webhooks.mailjet import MailjetTrackingWebhookView diff --git a/tests/test_mandrill_inbound.py b/tests/test_mandrill_inbound.py index cf875a5..7e34782 100644 --- a/tests/test_mandrill_inbound.py +++ b/tests/test_mandrill_inbound.py @@ -1,7 +1,7 @@ from textwrap import dedent +from unittest.mock import ANY from django.test import override_settings, tag -from mock import ANY from anymail.inbound import AnymailInboundMessage from anymail.signals import AnymailInboundEvent diff --git a/tests/test_mandrill_webhooks.py b/tests/test_mandrill_webhooks.py index fc5a677..a8677ba 100644 --- a/tests/test_mandrill_webhooks.py +++ b/tests/test_mandrill_webhooks.py @@ -3,12 +3,12 @@ import hmac import json from base64 import b64encode from datetime import datetime +from unittest.mock import ANY from urllib.parse import urljoin from django.core.exceptions import ImproperlyConfigured from django.test import override_settings, tag from django.utils.timezone import utc -from mock import ANY from anymail.signals import AnymailTrackingEvent from anymail.webhooks.mandrill import MandrillCombinedWebhookView, MandrillTrackingWebhookView diff --git a/tests/test_message.py b/tests/test_message.py index c26ba9d..ee4199b 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1,6 +1,7 @@ +from unittest.mock import patch + from django.core.mail import EmailMultiAlternatives from django.test import SimpleTestCase -from mock import patch from anymail.message import AnymailRecipientStatus, AnymailStatus, attach_inline_image diff --git a/tests/test_postal_inbound.py b/tests/test_postal_inbound.py index 416b634..1317b5e 100644 --- a/tests/test_postal_inbound.py +++ b/tests/test_postal_inbound.py @@ -2,9 +2,9 @@ import json import unittest from base64 import b64encode from textwrap import dedent +from unittest.mock import ANY from django.test import tag -from mock import ANY from anymail.exceptions import AnymailConfigurationError from anymail.inbound import AnymailInboundMessage diff --git a/tests/test_postal_webhooks.py b/tests/test_postal_webhooks.py index e60995b..2eef98f 100644 --- a/tests/test_postal_webhooks.py +++ b/tests/test_postal_webhooks.py @@ -2,10 +2,10 @@ import json import unittest from base64 import b64encode from datetime import datetime +from unittest.mock import ANY from django.test import tag from django.utils.timezone import utc -from mock import ANY from anymail.exceptions import AnymailConfigurationError from anymail.signals import AnymailTrackingEvent diff --git a/tests/test_postmark_inbound.py b/tests/test_postmark_inbound.py index 8ec13a6..91ee1e2 100644 --- a/tests/test_postmark_inbound.py +++ b/tests/test_postmark_inbound.py @@ -1,8 +1,8 @@ import json from base64 import b64encode +from unittest.mock import ANY from django.test import tag -from mock import ANY from anymail.exceptions import AnymailConfigurationError from anymail.inbound import AnymailInboundMessage diff --git a/tests/test_postmark_webhooks.py b/tests/test_postmark_webhooks.py index 31680cb..bbf12ee 100644 --- a/tests/test_postmark_webhooks.py +++ b/tests/test_postmark_webhooks.py @@ -1,9 +1,9 @@ import json from datetime import datetime +from unittest.mock import ANY from django.test import tag from django.utils.timezone import get_fixed_timezone, utc -from mock import ANY from anymail.exceptions import AnymailConfigurationError from anymail.signals import AnymailTrackingEvent diff --git a/tests/test_sendgrid_backend.py b/tests/test_sendgrid_backend.py index 3493e58..3305814 100644 --- a/tests/test_sendgrid_backend.py +++ b/tests/test_sendgrid_backend.py @@ -4,11 +4,11 @@ from datetime import date, datetime from decimal import Decimal from email.mime.base import MIMEBase from email.mime.image import MIMEImage +from unittest.mock import patch from django.core import mail from django.test import SimpleTestCase, override_settings, tag from django.utils.timezone import get_fixed_timezone, override as override_current_timezone -from mock import patch from anymail.exceptions import (AnymailAPIError, AnymailConfigurationError, AnymailSerializationError, AnymailUnsupportedFeature, AnymailWarning) diff --git a/tests/test_sendgrid_inbound.py b/tests/test_sendgrid_inbound.py index ecac317..68d0b98 100644 --- a/tests/test_sendgrid_inbound.py +++ b/tests/test_sendgrid_inbound.py @@ -1,9 +1,9 @@ import json from io import BytesIO from textwrap import dedent +from unittest.mock import ANY from django.test import tag -from mock import ANY from anymail.inbound import AnymailInboundMessage from anymail.signals import AnymailInboundEvent diff --git a/tests/test_sendgrid_webhooks.py b/tests/test_sendgrid_webhooks.py index 9d8750b..e1987ea 100644 --- a/tests/test_sendgrid_webhooks.py +++ b/tests/test_sendgrid_webhooks.py @@ -1,9 +1,9 @@ import json from datetime import datetime +from unittest.mock import ANY from django.test import tag from django.utils.timezone import utc -from mock import ANY from anymail.signals import AnymailTrackingEvent from anymail.webhooks.sendgrid import SendGridTrackingWebhookView diff --git a/tests/test_sendinblue_webhooks.py b/tests/test_sendinblue_webhooks.py index 307cf4b..dc902df 100644 --- a/tests/test_sendinblue_webhooks.py +++ b/tests/test_sendinblue_webhooks.py @@ -1,9 +1,9 @@ import json from datetime import datetime +from unittest.mock import ANY from django.test import tag from django.utils.timezone import utc -from mock import ANY from anymail.signals import AnymailTrackingEvent from anymail.webhooks.sendinblue import SendinBlueTrackingWebhookView diff --git a/tests/test_sparkpost_inbound.py b/tests/test_sparkpost_inbound.py index 0fdb04f..5ca17ac 100644 --- a/tests/test_sparkpost_inbound.py +++ b/tests/test_sparkpost_inbound.py @@ -1,9 +1,9 @@ import json from base64 import b64encode from textwrap import dedent +from unittest.mock import ANY from django.test import tag -from mock import ANY from anymail.inbound import AnymailInboundMessage from anymail.signals import AnymailInboundEvent diff --git a/tests/test_sparkpost_webhooks.py b/tests/test_sparkpost_webhooks.py index f243fff..9e8a174 100644 --- a/tests/test_sparkpost_webhooks.py +++ b/tests/test_sparkpost_webhooks.py @@ -1,9 +1,9 @@ import json from datetime import datetime +from unittest.mock import ANY from django.test import override_settings, tag from django.utils.timezone import utc -from mock import ANY from anymail.signals import AnymailTrackingEvent from anymail.webhooks.sparkpost import SparkPostTrackingWebhookView diff --git a/tests/webhook_cases.py b/tests/webhook_cases.py index 30b4b97..ac7a2a4 100644 --- a/tests/webhook_cases.py +++ b/tests/webhook_cases.py @@ -1,7 +1,7 @@ import base64 +from unittest.mock import create_autospec, ANY from django.test import override_settings, SimpleTestCase -from mock import create_autospec, ANY from anymail.exceptions import AnymailInsecureWebhookWarning from anymail.signals import tracking, inbound diff --git a/tox.ini b/tox.ini index 03723e1..156df96 100644 --- a/tox.ini +++ b/tox.ini @@ -27,14 +27,15 @@ deps = django22: django~=2.2.0 django30: django~=3.0.0 django31: django~=3.1.0 - django32: django>=3.2a1 + django32: django~=3.2.0 djangoDev: https://github.com/django/django/tarball/main old_urllib3: urllib3<1.25 - # testing dependencies (duplicates setup.py tests_require, less optional extras): - mock extras = + # install [test] extras, unconditionally + test + # install [esp_name] extras only when testing "all" or esp_name factor all,amazon_ses: amazon_ses - all,postal: cryptography + all,postal: postal setenv = # tell runtests.py to limit some test tags based on extras factor none: ANYMAIL_SKIP_TESTS=amazon_ses,postal