|
3 | 3 | from __future__ import unicode_literals |
4 | 4 |
|
5 | 5 | from datetime import date, datetime |
6 | | -from decimal import Decimal |
7 | 6 | from email.mime.base import MIMEBase |
8 | 7 | from email.mime.image import MIMEImage |
9 | 8 |
|
|
13 | 12 | from django.test.utils import override_settings |
14 | 13 | from django.utils.timezone import get_fixed_timezone, override as override_current_timezone |
15 | 14 |
|
16 | | -from anymail.exceptions import AnymailAPIError, AnymailSerializationError, AnymailUnsupportedFeature |
| 15 | +from anymail.exceptions import AnymailAPIError, AnymailUnsupportedFeature |
17 | 16 | from anymail.message import attach_inline_image_file |
18 | 17 |
|
19 | 18 | from .mock_requests_backend import RequestsBackendMockAPITestCase, SessionSharingTestCasesMixin |
@@ -270,12 +269,13 @@ class MailgunBackendAnymailFeatureTests(MailgunBackendMockAPITestCase): |
270 | 269 | """Test backend support for Anymail added features""" |
271 | 270 |
|
272 | 271 | def test_metadata(self): |
273 | | - self.message.metadata = {'user_id': "12345", 'items': ['mail', 'gun']} |
| 272 | + # Each metadata value is just a string; you can serialize your own JSON if you'd like. |
| 273 | + # (The Mailgun docs are a little confusing on this point.) |
| 274 | + self.message.metadata = {'user_id': "12345", 'items': '["mail","gun"]'} |
274 | 275 | self.message.send() |
275 | 276 | data = self.get_api_call_data() |
276 | | - # note values get serialized to json: |
277 | | - self.assertEqual(data['v:user_id'], '12345') # simple values are transmitted as-is |
278 | | - self.assertEqual(data['v:items'], '["mail", "gun"]') # complex values get json-serialized |
| 277 | + self.assertEqual(data['v:user_id'], '12345') |
| 278 | + self.assertEqual(data['v:items'], '["mail","gun"]') |
279 | 279 |
|
280 | 280 | def test_send_at(self): |
281 | 281 | utc_plus_6 = get_fixed_timezone(6 * 60) |
@@ -401,16 +401,8 @@ def test_send_unparsable_response(self): |
401 | 401 | self.assertEqual(self.message.anymail_status.recipients, {}) |
402 | 402 | self.assertEqual(self.message.anymail_status.esp_response, mock_response) |
403 | 403 |
|
404 | | - def test_json_serialization_errors(self): |
405 | | - """Try to provide more information about non-json-serializable data""" |
406 | | - self.message.metadata = {'total': Decimal('19.99')} |
407 | | - with self.assertRaises(AnymailSerializationError) as cm: |
408 | | - self.message.send() |
409 | | - print(self.get_api_call_data()) |
410 | | - err = cm.exception |
411 | | - self.assertIsInstance(err, TypeError) # compatibility with json.dumps |
412 | | - self.assertIn("Don't know how to send this data to Mailgun", str(err)) # our added context |
413 | | - self.assertIn("Decimal('19.99') is not JSON serializable", str(err)) # original message |
| 404 | + # test_json_serialization_errors: Mailgun payload isn't JSON, so we don't test this. |
| 405 | + # (Anything that requests can serialize as a form field will work with Mailgun) |
414 | 406 |
|
415 | 407 |
|
416 | 408 | class MailgunBackendRecipientsRefusedTests(MailgunBackendMockAPITestCase): |
|
0 commit comments