mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Improve and document JSON serialization for Mandrill API
* Add some context to exceptions on unserializable values (addresses #89). * Document need to format merge data (into something JSON-serializable). * Add RemovedInDjrill2 DeprecationWarning. * Deprecate blanket date/datetime serialization.
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from base64 import b64decode
|
||||
from datetime import date, datetime, timedelta, tzinfo
|
||||
from decimal import Decimal
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.image import MIMEImage
|
||||
import json
|
||||
@@ -507,6 +508,16 @@ class DjrillMandrillFeatureTests(DjrillBackendMockAPITestCase):
|
||||
self.assertEqual(sent, 0)
|
||||
self.assertIsNone(msg.mandrill_response)
|
||||
|
||||
def test_json_serialization_warnings(self):
|
||||
"""Try to provide more information about non-json-serializable data"""
|
||||
self.message.global_merge_vars = {'PRICE': Decimal('19.99')}
|
||||
with self.assertRaisesMessage(
|
||||
TypeError,
|
||||
"Decimal('19.99') is not JSON serializable in a Djrill message (perhaps "
|
||||
"it's a merge var?). Try converting it to a string or number first."
|
||||
):
|
||||
self.message.send()
|
||||
|
||||
|
||||
@override_settings(EMAIL_BACKEND="djrill.mail.backends.djrill.DjrillBackend")
|
||||
class DjrillImproperlyConfiguredTests(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user