-
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
120 additions
and
5 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 |
---|---|---|
|
@@ -111,7 +111,7 @@ def test_email_message(self): | |
cc=["[email protected]", "Also CC <[email protected]>"], | ||
headers={ | ||
"Reply-To": "[email protected]", | ||
"X-MyHeader": "my value", | ||
"x-my-header": "my value", | ||
"Message-ID": "[email protected]", | ||
}, | ||
) | ||
|
@@ -126,8 +126,8 @@ def test_email_message(self): | |
) | ||
self.assertEqual(data["cc"], ["[email protected]", "Also CC <[email protected]>"]) | ||
self.assertEqual(data["h:Reply-To"], "[email protected]") | ||
self.assertEqual(data["h:X-MyHeader"], "my value") | ||
self.assertEqual(data["h:Message-ID"], "[email protected]") | ||
self.assertEqual(data["h:X-My-Header"], "my value") | ||
self.assertEqual(data["h:Message-Id"], "[email protected]") | ||
# multiple recipients, but not a batch send: | ||
self.assertNotIn("recipient-variables", data) | ||
|
||
|
@@ -816,6 +816,51 @@ def test_conflicting_merge_data_with_merge_metadata_and_template(self): | |
): | ||
self.message.send() | ||
|
||
def test_merge_headers(self): | ||
# Per-recipient merge_headers uses the same recipient-variables mechanism | ||
# as above, using variable names starting with "h:" | ||
self.message.to = ["[email protected]", "Bob <[email protected]>"] | ||
self.message.extra_headers = { | ||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click", | ||
"List-Unsubscribe": "<mailto:[email protected]>", | ||
"X-Custom": "custom-default", | ||
} | ||
self.message.merge_headers = { | ||
"[email protected]": { | ||
"List-Unsubscribe": "<https://example.com/a/>", | ||
"X-No-Default": "custom-for-alice", | ||
}, | ||
"[email protected]": { | ||
"List-Unsubscribe": "<https://example.com/b/>", | ||
"X-Custom": "custom-for-bob", | ||
}, | ||
} | ||
self.message.send() | ||
|
||
data = self.get_api_call_data() | ||
# non-merge header has fixed value: | ||
self.assertEqual(data["h:List-Unsubscribe-Post"], "List-Unsubscribe=One-Click") | ||
# merge headers refer to recipient-variables: | ||
self.assertEqual(data["h:List-Unsubscribe"], "%recipient.h:List-Unsubscribe%") | ||
self.assertEqual(data["h:X-Custom"], "%recipient.h:X-Custom%") | ||
self.assertEqual(data["h:X-No-Default"], "%recipient.h:X-No-Default%") | ||
# recipient-variables populates them: | ||
self.assertJSONEqual( | ||
data["recipient-variables"], | ||
{ | ||
"[email protected]": { | ||
"h:List-Unsubscribe": "<https://example.com/a/>", | ||
"h:X-Custom": "custom-default", # from extra_headers | ||
"h:X-No-Default": "custom-for-alice", | ||
}, | ||
"[email protected]": { | ||
"h:List-Unsubscribe": "<https://example.com/b/>", | ||
"h:X-Custom": "custom-for-bob", | ||
"h:X-No-Default": "", # no default in extra_headers | ||
}, | ||
}, | ||
) | ||
|
||
def test_force_batch(self): | ||
# Mailgun uses presence of recipient-variables to indicate batch send | ||
self.message.to = ["[email protected]", "Bob <[email protected]>"] | ||
|
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 |
---|---|---|
|
@@ -201,6 +201,36 @@ def test_all_options(self): | |
# (We could try fetching the message from event["storage"]["url"] | ||
# to verify content and other headers.) | ||
|
||
def test_per_recipient_options(self): | ||
message = AnymailMessage( | ||
from_email=formataddr(("Test From", self.from_email)), | ||
to=["[email protected]", '"Recipient 2" <[email protected]>'], | ||
subject="Anymail Mailgun per-recipient options test", | ||
body="This is the text body", | ||
merge_metadata={ | ||
"[email protected]": {"meta1": "one", "meta2": "two"}, | ||
"[email protected]": {"meta1": "recipient 2"}, | ||
}, | ||
headers={ | ||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click", | ||
"List-Unsubscribe": "<mailto:[email protected]>", | ||
"X-Custom-Header": "default", | ||
}, | ||
merge_headers={ | ||
"[email protected]": { | ||
"List-Unsubscribe": "<https://example.com/a/>", | ||
"X-Custom-Header": "custom", | ||
}, | ||
"[email protected]": { | ||
"List-Unsubscribe": "<https://example.com/b/>", | ||
}, | ||
}, | ||
) | ||
message.send() | ||
recipient_status = message.anymail_status.recipients | ||
self.assertEqual(recipient_status["[email protected]"].status, "queued") | ||
self.assertEqual(recipient_status["[email protected]"].status, "queued") | ||
|
||
def test_stored_template(self): | ||
message = AnymailMessage( | ||
# name of a real template named in Anymail's Mailgun test account: | ||
|