Skip to content

Commit 9a68e04

Browse files
committed
add tests for new config variable
1 parent 582a8fb commit 9a68e04

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/aws/services/sns/test_sns.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,49 @@ def check_subscription():
30033003

30043004
retry(check_subscription, retries=PUBLICATION_RETRIES, sleep=PUBLICATION_TIMEOUT)
30053005

3006+
@markers.aws.only_localstack
3007+
def test_email_sender(
3008+
self,
3009+
sns_create_topic,
3010+
sns_subscription,
3011+
aws_client,
3012+
monkeypatch,
3013+
):
3014+
# make sure to reset all received emails in SES
3015+
requests.delete("http://localhost:4566/_aws/ses")
3016+
3017+
topic_arn = sns_create_topic()["TopicArn"]
3018+
sns_subscription(
3019+
TopicArn=topic_arn,
3020+
Protocol="email",
3021+
Endpoint="localstack@yopmail.com",
3022+
)
3023+
3024+
aws_client.sns.publish(
3025+
Message="Test message",
3026+
TopicArn=topic_arn,
3027+
)
3028+
3029+
def _get_messages(amount: int) -> list[dict]:
3030+
response = requests.get("http://localhost:4566/_aws/ses").json()
3031+
assert len(response["messages"]) == amount
3032+
return response["messages"]
3033+
3034+
messages = retry(lambda: _get_messages(1), retries=PUBLICATION_RETRIES, sleep=1)
3035+
# legacy default value, should be replaced at some point
3036+
assert messages[0]["Source"] == "admin@localstack.com"
3037+
requests.delete("http://localhost:4566/_aws/ses")
3038+
3039+
sender_address = "no-reply@sns.localstack.cloud"
3040+
monkeypatch.setattr(config, "SNS_SES_SENDER_ADDRESS", sender_address)
3041+
3042+
aws_client.sns.publish(
3043+
Message="Test message",
3044+
TopicArn=topic_arn,
3045+
)
3046+
messages = retry(lambda: _get_messages(1), retries=PUBLICATION_RETRIES, sleep=1)
3047+
assert messages[0]["Source"] == sender_address
3048+
30063049

30073050
class TestSNSPlatformEndpoint:
30083051
@markers.aws.only_localstack

0 commit comments

Comments
 (0)