|
8 | 8 | from botocore.exceptions import ClientError
|
9 | 9 |
|
10 | 10 | import localstack.config as config
|
| 11 | +from localstack.sdk.models import SesSentEmail |
11 | 12 | from localstack.services.ses.provider import EMAILS, EMAILS_ENDPOINT
|
12 | 13 | from localstack.testing.aws.util import is_aws_cloud
|
13 | 14 | from localstack.testing.pytest import markers
|
@@ -928,18 +929,18 @@ def test_ses_sns_topic_integration_send_email_ses_destination(
|
928 | 929 | ses_configuration_set_sns_event_destination,
|
929 | 930 | setup_email_addresses,
|
930 | 931 | aws_client,
|
| 932 | + localstack_sdk_aws_client, |
931 | 933 | ):
|
932 | 934 | """
|
933 | 935 | Validates that configure Event Destinations and sending an email does not trigger an infinite loop of sending
|
934 | 936 | SNS notifications that sends an email that would trigger SNS.
|
935 | 937 | """
|
936 | 938 |
|
| 939 | + sdk_client = localstack_sdk_aws_client() |
937 | 940 | sender_email_address, recipient_email_address = setup_email_addresses()
|
938 | 941 | config_set_name = f"config-set-{short_uid()}"
|
939 | 942 |
|
940 |
| - emails_url = config.internal_service_url() + EMAILS_ENDPOINT |
941 |
| - response = requests.delete(emails_url) |
942 |
| - assert response.status_code == 204 |
| 943 | + sdk_client.discard_ses_messages() |
943 | 944 |
|
944 | 945 | # create subscription to get notified about SES events
|
945 | 946 | topic_arn = sns_topic["Attributes"]["TopicArn"]
|
@@ -973,29 +974,25 @@ def test_ses_sns_topic_integration_send_email_ses_destination(
|
973 | 974 | ],
|
974 | 975 | )
|
975 | 976 |
|
976 |
| - def _get_emails(): |
977 |
| - _resp = requests.get(emails_url) |
978 |
| - return _resp.json()["messages"] |
979 |
| - |
980 |
| - poll_condition(lambda: len(_get_emails()) >= 4, timeout=3) |
981 |
| - requests.delete(emails_url, params={"id": send_email["MessageId"]}) |
| 977 | + poll_condition(lambda: len(sdk_client.get_ses_messages()) >= 4, timeout=3) |
| 978 | + sdk_client.discard_ses_messages(id_filter=send_email["MessageId"]) |
982 | 979 |
|
983 |
| - emails = _get_emails() |
| 980 | + emails: list[SesSentEmail] = sdk_client.get_ses_messages() |
984 | 981 | # we assert that we only received 3 emails
|
985 | 982 | assert len(emails) == 3
|
986 | 983 |
|
987 |
| - emails = sorted(emails, key=lambda x: x["Body"]["text_part"]) |
| 984 | + emails = sorted(emails, key=lambda x: x.body.text_part) |
988 | 985 | # the first email is the validation of SNS confirming the SES subscription
|
989 | 986 | ses_delivery_notification = emails[1]
|
990 | 987 | ses_send_notification = emails[2]
|
991 | 988 |
|
992 |
| - assert ses_delivery_notification["Subject"] == "SNS-Subscriber-Endpoint" |
993 |
| - delivery_payload = json.loads(ses_delivery_notification["Body"]["text_part"]) |
| 989 | + assert ses_delivery_notification.subject == "SNS-Subscriber-Endpoint" |
| 990 | + delivery_payload = json.loads(ses_delivery_notification.body.text_part) |
994 | 991 | assert delivery_payload["eventType"] == "Delivery"
|
995 | 992 | assert delivery_payload["mail"]["source"] == sender_email_address
|
996 | 993 |
|
997 |
| - assert ses_send_notification["Subject"] == "SNS-Subscriber-Endpoint" |
998 |
| - send_payload = json.loads(ses_send_notification["Body"]["text_part"]) |
| 994 | + assert ses_send_notification.subject == "SNS-Subscriber-Endpoint" |
| 995 | + send_payload = json.loads(ses_send_notification.body.text_part) |
999 | 996 | assert send_payload["eventType"] == "Send"
|
1000 | 997 | assert send_payload["mail"]["source"] == sender_email_address
|
1001 | 998 |
|
|
0 commit comments