mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Feature: Implement merge_headers
Implement and document `merge_headers` for all other ESPs that can support it. (See #371 for base and Amazon SES implementation.) Closes #374
This commit is contained in:
@@ -568,6 +568,43 @@ class BrevoBackendAnymailFeatureTests(BrevoBackendMockAPITestCase):
|
||||
{"notification_batch": "zx912"},
|
||||
)
|
||||
|
||||
def test_merge_headers(self):
|
||||
self.set_mock_response(json_data=self._mock_batch_response)
|
||||
self.message.to = ["alice@example.com", "Bob <bob@example.com>"]
|
||||
self.message.extra_headers = {
|
||||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
||||
"List-Unsubscribe": "<mailto:unsubscribe@example.com>",
|
||||
}
|
||||
self.message.merge_headers = {
|
||||
"alice@example.com": {
|
||||
"List-Unsubscribe": "<https://example.com/a/>",
|
||||
},
|
||||
"bob@example.com": {
|
||||
"List-Unsubscribe": "<https://example.com/b/>",
|
||||
},
|
||||
}
|
||||
|
||||
self.message.send()
|
||||
|
||||
data = self.get_api_call_json()
|
||||
versions = data["messageVersions"]
|
||||
self.assertEqual(len(versions), 2)
|
||||
self.assertEqual(
|
||||
versions[0]["headers"], {"List-Unsubscribe": "<https://example.com/a/>"}
|
||||
)
|
||||
self.assertEqual(
|
||||
versions[1]["headers"], {"List-Unsubscribe": "<https://example.com/b/>"}
|
||||
)
|
||||
self.assertNotIn("params", versions[0]) # because no merge_data
|
||||
# non-merge headers still in base data
|
||||
self.assertEqual(
|
||||
data["headers"],
|
||||
{
|
||||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
||||
"List-Unsubscribe": "<mailto:unsubscribe@example.com>",
|
||||
},
|
||||
)
|
||||
|
||||
def test_default_omits_options(self):
|
||||
"""Make sure by default we don't send any ESP-specific options.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user