"""Tests for the SES Connector.""" from unittest.mock import MagicMock, patch from notifications.config import SES_CHARSET, SES_SENDER from notifications.connectors.ses import send_email, send_html_email, send_html_email_bulk recipient = 'bburton@theorchard.com' subject = 'Hey hey hey' text_body = 'The Orchard!' @patch('notifications.connectors.ses.client') def test_send_email(mock_client): """Test send_email calls boto3 client.""" mock_client.send_email = MagicMock() send_email(subject=subject, text_body=text_body, recipient=recipient) mock_client.send_email.assert_called_with( Destination={'ToAddresses': [recipient]}, Message={ 'Body': {'Text': {'Charset': SES_CHARSET, 'Data': text_body}}, 'Subject': {'Charset': SES_CHARSET, 'Data': subject}, }, Source=SES_SENDER, ) @patch('notifications.connectors.ses.client') def test_send_html_email(mock_client): """Test send_html_email.""" mock_client.send_email = MagicMock() html = 'This message body contains HTML like link: Click.' send_html_email(subject=subject, body=html, recipient=recipient) mock_client.send_email.assert_called_with( Destination={'ToAddresses': [recipient]}, Message={ 'Body': {'Html': {'Charset': SES_CHARSET, 'Data': html}}, 'Subject': {'Charset': SES_CHARSET, 'Data': subject}, }, Source=SES_SENDER, ) @patch('notifications.connectors.ses.client') def test_send_html_email_with_bcc(mock_client): """Test send_html_email with BCC.""" mock_client.send_email = MagicMock() html = 'This message body contains HTML like link: Click.' bcc_recipients = ['test@orchard.com'] send_html_email(subject=subject, body=html, recipient=recipient, bcc=bcc_recipients) mock_client.send_email.assert_called_with( Destination={'ToAddresses': [recipient], 'BccAddresses': bcc_recipients}, Message={ 'Body': {'Html': {'Charset': SES_CHARSET, 'Data': html}}, 'Subject': {'Charset': SES_CHARSET, 'Data': subject}, }, Source=SES_SENDER, ) @patch('notifications.connectors.ses.client') def test_send_html_email_bulk(mock_client): """Test send_html_email_bulk.""" bcc_recipients = ['test@orchard.com', 'neo@orchard.com'] mock_client.send_email = MagicMock() html = 'This message body contains HTML like link: Click.' send_html_email_bulk( subject=subject, body=html, recipients=[ recipient, ], bcc=bcc_recipients, ) mock_client.send_email.assert_called_with( Destination={'ToAddresses': [recipient], 'BccAddresses': bcc_recipients}, Message={ 'Body': {'Html': {'Charset': SES_CHARSET, 'Data': html}}, 'Subject': {'Charset': SES_CHARSET, 'Data': subject}, }, Source=SES_SENDER, )