Skip to content

Commit 633f72a

Browse files
committed
add localstack sdk ses workflow for tests (#11)
1 parent 267ade9 commit 633f72a

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

tests/test_infra.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import boto3
33
import requests
4+
import localstack.sdk.aws
45
import json
56
import time
67

@@ -207,27 +208,25 @@ def calculate_user_score(user_answers):
207208

208209
print(f"Verified submission for {submission['Username']} with Score: {actual_score}")
209210

210-
ses_endpoint = "http://localhost:4566/_aws/ses"
211-
ses_response = requests.get(ses_endpoint)
212-
assert ses_response.status_code == 200
213-
ses_data = ses_response.json()
214-
215-
messages = ses_data.get('messages', [])
211+
client = localstack.sdk.aws.AWSClient()
216212
sender_email = "[email protected]"
217-
email_found = False
213+
messages = client.get_ses_messages(email_filter=sender_email)
218214

215+
email_found = False
219216
for message in messages:
220-
if message.get('Source') == sender_email:
217+
if message.source == sender_email:
221218
email_found = True
222-
assert 'Id' in message
223-
assert 'Region' in message
224-
assert 'Timestamp' in message
225-
assert 'Destination' in message
226-
assert 'Subject' in message
227-
assert 'Body' in message
228-
229-
body = message['Body']
230-
assert 'html_part' in body
231-
html_content = body['html_part']
219+
assert hasattr(message, 'id')
220+
assert hasattr(message, 'region')
221+
assert hasattr(message, 'timestamp')
222+
assert hasattr(message, 'destination')
223+
assert hasattr(message, 'subject')
224+
assert hasattr(message, 'body')
225+
226+
body = message.body
227+
assert hasattr(body, 'html_part')
228+
html_content = body.html_part
229+
230+
print(f"Email content: {html_content}")
232231

233232
assert email_found, f"No email found sent from {sender_email}"

0 commit comments

Comments
 (0)