-
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.
- Change in the name of the method that sets the template headers - Change in SES backend, made template headers optional for backward compatibility.
- Loading branch information
1 parent
453d755
commit 6cc3187
Showing
5 changed files
with
74 additions
and
22 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
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
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 |
---|---|---|
|
@@ -560,14 +560,64 @@ def test_merge_data(self): | |
): | ||
self.message.send() | ||
|
||
def test_merge_header_data(self): | ||
def test_merge_headers(self): | ||
# Amazon SES only supports merging when using templates (see below) | ||
self.message.merge_header_data = {} | ||
self.message.merge_headers = {} | ||
with self.assertRaisesMessage( | ||
AnymailUnsupportedFeature, "merge_header_data without template_id" | ||
AnymailUnsupportedFeature, "merge_headers without template_id" | ||
): | ||
self.message.send() | ||
|
||
@override_settings( | ||
# only way to use tags with template_id: | ||
ANYMAIL_AMAZON_SES_MESSAGE_TAG_NAME="Campaign" | ||
) | ||
def test_template_dont_add_merge_headers(self): | ||
"""With template_id, Anymail switches to SESv2 SendBulkEmail""" | ||
# SendBulkEmail uses a completely different API call and payload | ||
# structure, so this re-tests a bunch of Anymail features that were handled | ||
# differently above. (See test_amazon_ses_integration for a more realistic | ||
# template example.) | ||
raw_response = { | ||
"BulkEmailEntryResults": [ | ||
{ | ||
"Status": "SUCCESS", | ||
"MessageId": "1111111111111111-bbbbbbbb-3333-7777", | ||
}, | ||
{ | ||
"Status": "ACCOUNT_DAILY_QUOTA_EXCEEDED", | ||
"Error": "Daily message quota exceeded", | ||
}, | ||
], | ||
"ResponseMetadata": self.DEFAULT_SEND_RESPONSE["ResponseMetadata"], | ||
} | ||
self.set_mock_response(raw_response, operation_name="send_bulk_email") | ||
message = AnymailMessage( | ||
template_id="welcome_template", | ||
from_email='"Example, Inc." <[email protected]>', | ||
to=["[email protected]", "罗伯特 <[email protected]>"], | ||
cc=["[email protected]"], | ||
reply_to=["[email protected]", "Reply 2 <[email protected]>"], | ||
merge_data={ | ||
"[email protected]": {"name": "Alice", "group": "Developers"}, | ||
"[email protected]": {"name": "Bob"}, # and leave group undefined | ||
"[email protected]": {"name": "Not a recipient for this message"}, | ||
}, | ||
merge_global_data={"group": "Users", "site": "ExampleCo"}, | ||
# (only works with AMAZON_SES_MESSAGE_TAG_NAME when using template): | ||
tags=["WelcomeVariantA"], | ||
envelope_sender="[email protected]", | ||
esp_extra={ | ||
"FromEmailAddressIdentityArn": ( | ||
"arn:aws:ses:us-east-1:123456789012:identity/example.com" | ||
) | ||
}, | ||
) | ||
message.send() | ||
|
||
params = self.get_send_params(operation_name="send_bulk_email") | ||
self.assertNotIn("ReplacementHeaders", params["BulkEmailEntries"][0]) | ||
|
||
@override_settings( | ||
# only way to use tags with template_id: | ||
ANYMAIL_AMAZON_SES_MESSAGE_TAG_NAME="Campaign" | ||
|
@@ -603,7 +653,7 @@ def test_template(self): | |
"[email protected]": {"name": "Bob"}, # and leave group undefined | ||
"[email protected]": {"name": "Not a recipient for this message"}, | ||
}, | ||
merge_header_data={ | ||
merge_headers={ | ||
"[email protected]": [ | ||
{"Name": "List-Unsubscribe-Post", "Value": "https://xyz.com/a/"} | ||
], | ||
|