Merge pull request #2724 from jayudey-vertex/account-for-types

Handle map or list parameters in sns processing
This commit is contained in:
Bert Blommers 2020-02-05 16:13:59 +00:00 committed by GitHub
commit fa17b748f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 7 deletions

View File

@ -148,11 +148,15 @@ class SESBackend(BaseBackend):
def __type_of_message__(self, destinations): def __type_of_message__(self, destinations):
"""Checks the destination for any special address that could indicate delivery, """Checks the destination for any special address that could indicate delivery,
complaint or bounce like in SES simulator""" complaint or bounce like in SES simulator"""
if isinstance(destinations, list):
alladdress = destinations
else:
alladdress = ( alladdress = (
destinations.get("ToAddresses", []) destinations.get("ToAddresses", [])
+ destinations.get("CcAddresses", []) + destinations.get("CcAddresses", [])
+ destinations.get("BccAddresses", []) + destinations.get("BccAddresses", [])
) )
for addr in alladdress: for addr in alladdress:
if SESFeedback.SUCCESS_ADDR in addr: if SESFeedback.SUCCESS_ADDR in addr:
return SESFeedback.DELIVERY return SESFeedback.DELIVERY

View File

@ -40,6 +40,8 @@ def __setup_feedback_env__(
) )
# Verify SES domain # Verify SES domain
ses_conn.verify_domain_identity(Domain=domain) ses_conn.verify_domain_identity(Domain=domain)
# Specify email address to allow for raw e-mails to be processed
ses_conn.verify_email_identity(EmailAddress="test@example.com")
# Setup SES notification topic # Setup SES notification topic
if expected_msg is not None: if expected_msg is not None:
ses_conn.set_identity_notification_topic( ses_conn.set_identity_notification_topic(
@ -47,7 +49,7 @@ def __setup_feedback_env__(
) )
def __test_sns_feedback__(addr, expected_msg): def __test_sns_feedback__(addr, expected_msg, raw_email=False):
region_name = "us-east-1" region_name = "us-east-1"
ses_conn = boto3.client("ses", region_name=region_name) ses_conn = boto3.client("ses", region_name=region_name)
sns_conn = boto3.client("sns", region_name=region_name) sns_conn = boto3.client("sns", region_name=region_name)
@ -73,6 +75,17 @@ def __test_sns_feedback__(addr, expected_msg):
"Body": {"Text": {"Data": "test body"}}, "Body": {"Text": {"Data": "test body"}},
}, },
) )
if raw_email:
kwargs.pop("Message")
kwargs.pop("Destination")
kwargs.update(
{
"Destinations": [addr + "@" + domain],
"RawMessage": {"Data": bytearray("raw_email", "utf-8")},
}
)
ses_conn.send_raw_email(**kwargs)
else:
ses_conn.send_email(**kwargs) ses_conn.send_email(**kwargs)
# Wait for messages in the queues # Wait for messages in the queues
@ -112,3 +125,12 @@ def test_sns_feedback_complaint():
@mock_ses @mock_ses
def test_sns_feedback_delivery(): def test_sns_feedback_delivery():
__test_sns_feedback__(SESFeedback.SUCCESS_ADDR, SESFeedback.DELIVERY) __test_sns_feedback__(SESFeedback.SUCCESS_ADDR, SESFeedback.DELIVERY)
@mock_sqs
@mock_sns
@mock_ses
def test_sns_feedback_delivery_raw_email():
__test_sns_feedback__(
SESFeedback.SUCCESS_ADDR, SESFeedback.DELIVERY, raw_email=True
)