Skip to content

Commit

Permalink
add localstack sdk ses workflow for tests (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshCasper committed Nov 11, 2024
1 parent 267ade9 commit 633f72a
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions tests/test_infra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import boto3
import requests
import localstack.sdk.aws
import json
import time

Expand Down Expand Up @@ -207,27 +208,25 @@ def calculate_user_score(user_answers):

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

ses_endpoint = "http://localhost:4566/_aws/ses"
ses_response = requests.get(ses_endpoint)
assert ses_response.status_code == 200
ses_data = ses_response.json()

messages = ses_data.get('messages', [])
client = localstack.sdk.aws.AWSClient()
sender_email = "[email protected]"
email_found = False
messages = client.get_ses_messages(email_filter=sender_email)

email_found = False
for message in messages:
if message.get('Source') == sender_email:
if message.source == sender_email:
email_found = True
assert 'Id' in message
assert 'Region' in message
assert 'Timestamp' in message
assert 'Destination' in message
assert 'Subject' in message
assert 'Body' in message

body = message['Body']
assert 'html_part' in body
html_content = body['html_part']
assert hasattr(message, 'id')
assert hasattr(message, 'region')
assert hasattr(message, 'timestamp')
assert hasattr(message, 'destination')
assert hasattr(message, 'subject')
assert hasattr(message, 'body')

body = message.body
assert hasattr(body, 'html_part')
html_content = body.html_part

print(f"Email content: {html_content}")

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

0 comments on commit 633f72a

Please sign in to comment.