-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -605,6 +605,58 @@ def test_merge_metadata(self): | |
) | ||
self.assertEqual(data["metadata"], {"notification_batch": "zx912"}) | ||
|
||
def test_merge_headers(self): | ||
self.set_mock_result(accepted=2) | ||
self.message.to = ["[email protected]", "Bob <[email protected]>"] | ||
self.message.extra_headers = { | ||
"X-Custom-1": "custom 1", | ||
"X-Custom-2": "custom 2 (default)", | ||
} | ||
self.message.merge_headers = { | ||
"[email protected]": { | ||
"X-Custom-2": "custom 2 alice", | ||
"X-Custom-3": "custom 3 alice", | ||
}, | ||
"[email protected]": {"X-Custom-2": "custom 2 bob"}, | ||
} | ||
|
||
self.message.send() | ||
data = self.get_api_call_json() | ||
recipients = data["recipients"] | ||
self.assertEqual(len(recipients), 2) | ||
self.assertEqual(recipients[0]["address"]["email"], "[email protected]") | ||
self.assertEqual( | ||
recipients[0]["substitution_data"], | ||
{ | ||
"Header__X_Custom_2": "custom 2 alice", | ||
"Header__X_Custom_3": "custom 3 alice", | ||
}, | ||
) | ||
self.assertEqual(recipients[1]["address"]["email"], "[email protected]") | ||
self.assertEqual( | ||
recipients[1]["substitution_data"], | ||
{ | ||
"Header__X_Custom_2": "custom 2 bob", | ||
}, | ||
) | ||
# Indirect merge_headers through template substitutions: | ||
self.assertEqual( | ||
data["content"]["headers"], | ||
{ | ||
"X-Custom-1": "custom 1", # (not a merge_header, value unchanged) | ||
"X-Custom-2": "{{Header__X_Custom_2}}", | ||
"X-Custom-3": "{{Header__X_Custom_3}}", | ||
}, | ||
) | ||
# Defaults for merge_headers in global substitution_data: | ||
self.assertEqual( | ||
data["substitution_data"], | ||
{ | ||
"Header__X_Custom_2": "custom 2 (default)", | ||
# No default specified for X-Custom-3; SparkPost will use empty string | ||
}, | ||
) | ||
|
||
def test_default_omits_options(self): | ||
"""Make sure by default we don't send any ESP-specific options. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,19 @@ def test_merge_data(self): | |
"[email protected]": {"value": "two"}, | ||
}, | ||
merge_global_data={"global": "global_value"}, | ||
merge_metadata={ | ||
"[email protected]": {"meta1": "one"}, | ||
"[email protected]": {"meta1": "two"}, | ||
}, | ||
headers={ | ||
"X-Custom": "custom header default", | ||
}, | ||
merge_headers={ | ||
# (Note that SparkPost doesn't support custom List-Unsubscribe headers) | ||
"[email protected]": { | ||
"X-Custom": "custom header one", | ||
}, | ||
}, | ||
) | ||
message.send() | ||
recipient_status = message.anymail_status.recipients | ||
|