mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Add merge_metadata for other ESPs
Support merge_metadata in Mailgun, Mailjet, Mandrill, Postmark, SparkPost, and Test backends. (SendGrid covered in earlier PR.) Also: * Add `merge_metadata` to AnymailMessage, AnymailMessageMixin * Add `is_batch()` logic to BasePayload, for consistent handling * Docs Note: Mailjet implementation switches *all* batch sending from their "Recipients" field to to the "Messages" array bulk sending option. This allows an independent payload for each batch recipient. In addition to supporting merge_metadata, this also removes the prior limitation on mixing Cc/Bcc with merge_data. Closes #141.
This commit is contained in:
@@ -379,7 +379,25 @@ class MandrillBackendAnymailFeatureTests(MandrillBackendMockAPITestCase):
|
||||
{'name': "group", 'content': "Users"},
|
||||
{'name': "site", 'content': "ExampleCo"},
|
||||
])
|
||||
self.assertEqual(data['message']['preserve_recipients'], False) # we force with merge_data
|
||||
self.assertIs(data['message']['preserve_recipients'], False) # merge_data implies batch
|
||||
|
||||
def test_merge_metadata(self):
|
||||
self.message.to = ['alice@example.com', 'Bob <bob@example.com>']
|
||||
self.message.merge_metadata = {
|
||||
'alice@example.com': {'order_id': 123, 'tier': 'premium'},
|
||||
'bob@example.com': {'order_id': 678},
|
||||
}
|
||||
self.message.metadata = {'notification_batch': 'zx912'}
|
||||
self.message.send()
|
||||
data = self.get_api_call_json()
|
||||
self.assertCountEqual(data['message']['recipient_metadata'], [{
|
||||
'rcpt': 'alice@example.com',
|
||||
'values': {'order_id': 123, 'tier': 'premium'},
|
||||
}, {
|
||||
'rcpt': 'bob@example.com',
|
||||
'values': {'order_id': 678},
|
||||
}])
|
||||
self.assertIs(data['message']['preserve_recipients'], False) # merge_metadata implies batch
|
||||
|
||||
def test_missing_from(self):
|
||||
"""Make sure a missing from_email omits from* from API call.
|
||||
|
||||
Reference in New Issue
Block a user