from unittest.mock import MagicMock import pytest from src.ses_client import SESClient @pytest.fixture def ses_client(): client = SESClient(region="us-east-1") client.client = MagicMock() client.client.send_email.return_value = {"MessageId": "msg-001"} return client class TestSESClientSendEmail: def test_source_arn_added_to_kwargs_when_provided(self, ses_client): """SourceArn must be present in the boto3 call when source_arn is given.""" ses_client.send_email( to_addresses=["alice@example.com"], subject="Test", body_text="Hello", from_address="sender@example.com", source_arn="arn:aws:ses:us-east-1:123456789012:identity/sender@example.com", ) call_kwargs = ses_client.client.send_email.call_args.kwargs assert call_kwargs["SourceArn"] == "arn:aws:ses:us-east-1:123456789012:identity/sender@example.com" def test_source_arn_absent_from_kwargs_when_none(self, ses_client): """SourceArn must not appear in the boto3 call when source_arn is None.""" ses_client.send_email( to_addresses=["alice@example.com"], subject="Test", body_text="Hello", from_address="sender@example.com", source_arn=None, ) call_kwargs = ses_client.client.send_email.call_args.kwargs assert "SourceArn" not in call_kwargs def test_source_arn_absent_from_kwargs_when_omitted(self, ses_client): """SourceArn must not appear in the boto3 call when source_arn is not passed at all.""" ses_client.send_email( to_addresses=["alice@example.com"], subject="Test", body_text="Hello", from_address="sender@example.com", ) call_kwargs = ses_client.client.send_email.call_args.kwargs assert "SourceArn" not in call_kwargs def test_recipients_sent_as_bcc(self, ses_client): """Addresses must go into BccAddresses, not ToAddresses, to avoid exposing recipients.""" ses_client.send_email( to_addresses=["alice@example.com", "bob@example.com"], subject="Test", body_text="Hello", from_address="sender@example.com", ) call_kwargs = ses_client.client.send_email.call_args.kwargs assert call_kwargs["Destination"] == {"BccAddresses": ["alice@example.com", "bob@example.com"]} def test_returns_message_id(self, ses_client): result = ses_client.send_email( to_addresses=["alice@example.com"], subject="Test", body_text="Hello", from_address="sender@example.com", ) assert result == "msg-001"