Skip to content

Commit 30cee15

Browse files
committed
use sdk in the test
1 parent 9420725 commit 30cee15

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tests/aws/services/ses/test_ses.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from botocore.exceptions import ClientError
99

1010
import localstack.config as config
11+
from localstack.sdk.models import SesSentEmail
1112
from localstack.services.ses.provider import EMAILS, EMAILS_ENDPOINT
1213
from localstack.testing.aws.util import is_aws_cloud
1314
from localstack.testing.pytest import markers
@@ -928,18 +929,18 @@ def test_ses_sns_topic_integration_send_email_ses_destination(
928929
ses_configuration_set_sns_event_destination,
929930
setup_email_addresses,
930931
aws_client,
932+
localstack_sdk_aws_client,
931933
):
932934
"""
933935
Validates that configure Event Destinations and sending an email does not trigger an infinite loop of sending
934936
SNS notifications that sends an email that would trigger SNS.
935937
"""
936938

939+
sdk_client = localstack_sdk_aws_client()
937940
sender_email_address, recipient_email_address = setup_email_addresses()
938941
config_set_name = f"config-set-{short_uid()}"
939942

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()
943944

944945
# create subscription to get notified about SES events
945946
topic_arn = sns_topic["Attributes"]["TopicArn"]
@@ -973,29 +974,25 @@ def test_ses_sns_topic_integration_send_email_ses_destination(
973974
],
974975
)
975976

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"])
982979

983-
emails = _get_emails()
980+
emails: list[SesSentEmail] = sdk_client.get_ses_messages()
984981
# we assert that we only received 3 emails
985982
assert len(emails) == 3
986983

987-
emails = sorted(emails, key=lambda x: x["Body"]["text_part"])
984+
emails = sorted(emails, key=lambda x: x.body.text_part)
988985
# the first email is the validation of SNS confirming the SES subscription
989986
ses_delivery_notification = emails[1]
990987
ses_send_notification = emails[2]
991988

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)
994991
assert delivery_payload["eventType"] == "Delivery"
995992
assert delivery_payload["mail"]["source"] == sender_email_address
996993

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)
999996
assert send_payload["eventType"] == "Send"
1000997
assert send_payload["mail"]["source"] == sender_email_address
1001998

0 commit comments

Comments
 (0)