def test_send_mail(self): # Send a test email, and ensure that the calls passed along to boto are correct. fake_conn = enable_fake_ses_connection() mail.send_mail( 'fake_subject', 'fake_body', '*****@*****.**', ['*****@*****.**'], fail_silently=False, ) # Check that boto.SESConnection.send_raw_email was called correctly. calls = fake_conn.function_calls['send_raw_email'] self.assertEqual(len(calls), 1) args, kwargs = calls[0] self.assertEqual(args, ()) self.assertEqual(kwargs['source'], '*****@*****.**') self.assertEqual(kwargs['destinations'], ['*****@*****.**']) raw_message = kwargs['raw_message'] assert raw_message.startswith( 'Content-Type: text/plain; charset="utf-8"\n' 'MIME-Version: 1.0\n' 'Content-Transfer-Encoding: quoted-printable\n' 'Subject: fake_subject\n' 'From: [email protected]\n' 'To: [email protected]\n' ) assert raw_message.endswith('\nfake_body')
def test_send_mail_blacklisted(self): # Send a test email to a mocked blacklisted address, and ensure that it # raises a useful exception. fake_conn = enable_fake_ses_connection() fake_conn.blacklist.append('*****@*****.**') self.assertRaises( BlacklistedAddressException, lambda: mail.send_mail( 'fake_subject', 'fake_body', '*****@*****.**', ['*****@*****.**'], fail_silently=False, ) ) # Check that boto.SESConnection.send_raw_email was called correctly. calls = fake_conn.function_calls['send_raw_email'] self.assertEqual(len(calls), 1) args, kwargs = calls[0] self.assertEqual(args, ()) self.assertEqual(kwargs['source'], '*****@*****.**') self.assertEqual(kwargs['destinations'], ['*****@*****.**']) raw_message = kwargs['raw_message'] assert raw_message.startswith( 'Content-Type: text/plain; charset="utf-8"\n' 'MIME-Version: 1.0\n' 'Content-Transfer-Encoding: quoted-printable\n' 'Subject: fake_subject\n' 'From: [email protected]\n' 'To: [email protected]\n' ) assert raw_message.endswith('\nfake_body')