|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from aws_lambda_powertools.utilities.parser.models import SesModel, SesRecordModel |
2 | 4 | from tests.functional.utils import load_event |
3 | 5 |
|
@@ -117,3 +119,45 @@ def test_ses_trigger_event_with_optional_common_headers(): |
117 | 119 | assert common_headers.bcc == ["bcc@example.com"] |
118 | 120 | assert common_headers.sender == ["sender@example.com"] |
119 | 121 | assert common_headers.reply_to == ["reply@example.com"] |
| 122 | + |
| 123 | + |
| 124 | +@pytest.mark.parametrize("invocation_type", ["Event", "RequestResponse"]) |
| 125 | +def test_ses_trigger_event_with_invocation_type(invocation_type): |
| 126 | + # GIVEN an SES event from a Lambda action with either documented invocation type |
| 127 | + raw_event = load_event("sesEvent.json") |
| 128 | + raw_event["Records"][0]["ses"]["receipt"]["action"]["invocationType"] = invocation_type |
| 129 | + |
| 130 | + # WHEN parsing the event |
| 131 | + action = SesModel(**raw_event).Records[0].ses.receipt.action |
| 132 | + |
| 133 | + # THEN the invocation type is kept |
| 134 | + assert action.invocationType == invocation_type |
| 135 | + |
| 136 | + |
| 137 | +def test_ses_trigger_event_without_invocation_type(): |
| 138 | + # GIVEN an SES event whose Lambda action has no invocation type |
| 139 | + raw_event = load_event("sesEvent.json") |
| 140 | + del raw_event["Records"][0]["ses"]["receipt"]["action"]["invocationType"] |
| 141 | + |
| 142 | + # WHEN parsing the event |
| 143 | + action = SesModel(**raw_event).Records[0].ses.receipt.action |
| 144 | + |
| 145 | + # THEN the invocation type is None |
| 146 | + assert action.invocationType is None |
| 147 | + |
| 148 | + |
| 149 | +def test_ses_trigger_event_without_common_headers(): |
| 150 | + # GIVEN an SES event for an email without any common headers (SES only sends the ones the email has) |
| 151 | + raw_event = load_event("sesEvent.json") |
| 152 | + raw_event["Records"][0]["ses"]["mail"]["commonHeaders"] = {} |
| 153 | + |
| 154 | + # WHEN parsing the event |
| 155 | + common_headers = SesModel(**raw_event).Records[0].ses.mail.commonHeaders |
| 156 | + |
| 157 | + # THEN every common header is None |
| 158 | + assert common_headers.header_from is None |
| 159 | + assert common_headers.to is None |
| 160 | + assert common_headers.returnPath is None |
| 161 | + assert common_headers.messageId is None |
| 162 | + assert common_headers.date is None |
| 163 | + assert common_headers.subject is None |
0 commit comments