From 23800657b8d3f095b07ea711826401fa0412e5e2 Mon Sep 17 00:00:00 2001 From: medmunds Date: Sun, 22 Jan 2017 11:21:58 -0800 Subject: [PATCH] Support Python 3.6 with Django 1.11-alpha Only real problem is in json serialization tests: Python 3.6 [changed][1] the json serialization error message to use the object's class name rather than its repr. E.g.: "Decimal('19.99') is not JSON serializable" becomes: "Object of type 'Decimal' is not JSON serializable" Update tests that looked for specific serialization error message to just look for the word "Decimal" instead. (Works with all Python versions.) [1]: https://bugs.python.org/issue26623 --- .travis.yml | 6 +++--- tests/test_mandrill_backend.py | 2 +- tests/test_postmark_backend.py | 4 ++-- tests/test_sendgrid_backend.py | 4 ++-- tests/test_sendgrid_v2_backend.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index fded554..8423008 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,9 +30,9 @@ matrix: - { env: DJANGO="--pre django", python: 3.5 } - { env: DJANGO="--pre django", python: 3.6 } - { env: DJANGO="--pre django", python: pypy } - - allow_failures: - - python: 3.6 + # allow_failures: + # - env: DJANGO="--pre django" + # - python: 3.6 cache: directories: diff --git a/tests/test_mandrill_backend.py b/tests/test_mandrill_backend.py index 1f4cc97..8a486fb 100644 --- a/tests/test_mandrill_backend.py +++ b/tests/test_mandrill_backend.py @@ -525,7 +525,7 @@ class MandrillBackendAnymailFeatureTests(MandrillBackendMockAPITestCase): err = cm.exception self.assertIsInstance(err, TypeError) # compatibility with json.dumps self.assertIn("Don't know how to send this data to Mandrill", str(err)) # our added context - self.assertIn("Decimal('19.99') is not JSON serializable", str(err)) # original message + self.assertRegex(str(err), r"Decimal.*is not JSON serializable") # original message class MandrillBackendRecipientsRefusedTests(MandrillBackendMockAPITestCase): diff --git a/tests/test_postmark_backend.py b/tests/test_postmark_backend.py index 2390d98..9332f2b 100644 --- a/tests/test_postmark_backend.py +++ b/tests/test_postmark_backend.py @@ -124,7 +124,7 @@ class PostmarkBackendStandardEmailTests(PostmarkBackendMockAPITestCase): def test_extra_headers_serialization_error(self): self.message.extra_headers = {'X-Custom': Decimal(12.5)} - with self.assertRaisesMessage(AnymailSerializationError, "Decimal('12.5')"): + with self.assertRaisesMessage(AnymailSerializationError, "Decimal"): self.message.send() def test_reply_to(self): @@ -457,7 +457,7 @@ class PostmarkBackendAnymailFeatureTests(PostmarkBackendMockAPITestCase): err = cm.exception self.assertIsInstance(err, TypeError) # compatibility with json.dumps self.assertIn("Don't know how to send this data to Postmark", str(err)) # our added context - self.assertIn("Decimal('19.99') is not JSON serializable", str(err)) # original message + self.assertRegex(str(err), r"Decimal.*is not JSON serializable") # original message class PostmarkBackendRecipientsRefusedTests(PostmarkBackendMockAPITestCase): diff --git a/tests/test_sendgrid_backend.py b/tests/test_sendgrid_backend.py index bca1057..a6a47fc 100644 --- a/tests/test_sendgrid_backend.py +++ b/tests/test_sendgrid_backend.py @@ -156,7 +156,7 @@ class SendGridBackendStandardEmailTests(SendGridBackendMockAPITestCase): def test_extra_headers_serialization_error(self): self.message.extra_headers = {'X-Custom': Decimal(12.5)} - with self.assertRaisesMessage(AnymailSerializationError, "Decimal('12.5')"): + with self.assertRaisesMessage(AnymailSerializationError, "Decimal"): self.message.send() def test_reply_to(self): @@ -591,7 +591,7 @@ class SendGridBackendAnymailFeatureTests(SendGridBackendMockAPITestCase): err = cm.exception self.assertIsInstance(err, TypeError) # compatibility with json.dumps self.assertIn("Don't know how to send this data to SendGrid", str(err)) # our added context - self.assertIn("Decimal('19.99') is not JSON serializable", str(err)) # original message + self.assertRegex(str(err), r"Decimal.*is not JSON serializable") # original message @override_settings(ANYMAIL_SENDGRID_WORKAROUND_NAME_QUOTE_BUG=False) def test_undocumented_workaround_name_quote_bug_setting(self): diff --git a/tests/test_sendgrid_v2_backend.py b/tests/test_sendgrid_v2_backend.py index a85ba4a..22ec41b 100644 --- a/tests/test_sendgrid_v2_backend.py +++ b/tests/test_sendgrid_v2_backend.py @@ -163,7 +163,7 @@ class SendGridBackendStandardEmailTests(SendGridBackendMockAPITestCase): def test_extra_headers_serialization_error(self): self.message.extra_headers = {'X-Custom': Decimal(12.5)} - with self.assertRaisesMessage(AnymailSerializationError, "Decimal('12.5')"): + with self.assertRaisesMessage(AnymailSerializationError, "Decimal"): self.message.send() def test_reply_to(self): @@ -592,7 +592,7 @@ class SendGridBackendAnymailFeatureTests(SendGridBackendMockAPITestCase): err = cm.exception self.assertIsInstance(err, TypeError) # compatibility with json.dumps self.assertIn("Don't know how to send this data to SendGrid", str(err)) # our added context - self.assertIn("Decimal('19.99') is not JSON serializable", str(err)) # original message + self.assertRegex(str(err), r"Decimal.*is not JSON serializable") # original message class SendGridBackendRecipientsRefusedTests(SendGridBackendMockAPITestCase):