from email.mime.multipart import MIMEMultipart import pytest from ...src import aws, config from ...src.constants import SesResponse, EmailPayload, AwsMailboxSimulators @pytest.mark.parametrize( "factory_func,service_name", [ (aws.new_ses_client, aws.aws.AWSServices.SES), (aws.new_s3_client, aws.aws.AWSServices.S3), ], ) def test_new_service_client(factory_func, service_name): """Test that a new AWS Service client can be created.""" client = factory_func() assert client.meta.region_name, f"Expected object to be a {service_name} client." @pytest.fixture(scope="module") def sample_raw_email(): """Sample MIME Multipart raw email.""" msg = MIMEMultipart() msg[EmailPayload.FROM] = config.EMAIL_FROM msg[EmailPayload.TO] = AwsMailboxSimulators.SUCCESS msg[EmailPayload.SUBJECT] = "Test Email" return msg def test_send_raw_email(sample_raw_email): """Test that the send_raw_email function works. This test uses AWS SES Mailbox Simulator to test real email being sent but to an automated test account provided by AWS. See: https://docs.aws.amazon.com/ses/latest/dg/send-an-email-from-console.html """ response = aws.send_raw_email([AwsMailboxSimulators.SUCCESS], sample_raw_email) assert response[SesResponse.RESPONSE_METADATA][SesResponse.HTTP_STATUS_CODE] == 200