def test_success(): # Simulates the recipient's email provider accepting the email. address = '*****@*****.**' assert not close_to_quota_max(), 'Too close to max send quota' resp = _run_mailbox_simulator(address) assert resp['ResponseMetadata']['HTTPStatusCode'] == 200,\ 'HTTP Status Code %d' % resp['ResponseMetadata']['HTTPStatusCode']
def test_actual_email(): assert not close_to_quota_max(),\ 'Can\'t test email to real address, too close to max quota' assert actual_test_receiver, 'EMAIL_TEST_RECEIVER not set in environment' options['recipients'] = [actual_test_receiver] resp = send_email(**options) assert resp['ResponseMetadata']['HTTPStatusCode'] == 200,\ 'HTTP Status Code %d' % resp['ResponseMetadata']['HTTPStatusCode'] print(f'Test only passes if {actual_test_receiver} saw their email.')
def test_suppression_list(): # Simulates a hard bounce by Amazon SES generating a hard bounce as if # the recipient's address is on the Amazon SES suppression list. address = '*****@*****.**' assert not close_to_quota_max(), 'Too close to max send quota' resp = _run_mailbox_simulator(address) dt_sent_email = datetime.utcnow().replace(tzinfo=timezone.utc) assert resp['ResponseMetadata']['HTTPStatusCode'] == 200,\ 'HTTP Status Code %d' % resp['ResponseMetadata']['HTTPStatusCode'] sleep(2) feedback_content = _get_latest_feedback_email_content() assert 'Content-Description: Delivery Status Notification'\ in feedback_content assert html_body_rn in feedback_content assert resp['MessageId'] in feedback_content key, dt_feedback = _get_latest_email_keys('feedback', w_dt=True)[-1] assert dt_sent_email < dt_feedback
def test_auto_response(): # Tests automated replies, e.g. "I'm Out Of The Office until Monday" # Simulates the recipient's email provider accepting the email and # sending an automatic response. address = '*****@*****.**' assert not close_to_quota_max(), 'Too close to max send quota' resp = _run_mailbox_simulator(address) dt_sent_email = datetime.utcnow().replace(tzinfo=timezone.utc) assert resp['ResponseMetadata']['HTTPStatusCode'] == 200,\ 'HTTP Status Code %d' % resp['ResponseMetadata']['HTTPStatusCode'] print('Sleeping to let email be stored on s3..') sleep(3) feedback_content = _get_latest_feedback_email_content() key, dt_feedback = _get_latest_email_keys('feedback', w_dt=True)[-1] assert dt_sent_email < dt_feedback # Test if we have the correct email assert resp['MessageId'] in feedback_content assert notifications_return_default in feedback_content assert 'Emmaa email nosetest' in feedback_content
def test_bounce(): # Simulates the recipient's email provider rejecting your email with an # SMTP 550 5.1.1 ("Unknown User") response code. address = '*****@*****.**' assert not close_to_quota_max(), 'Too close to max send quota' resp = _run_mailbox_simulator(address) dt_sent_email = datetime.utcnow().replace(tzinfo=timezone.utc) assert resp['ResponseMetadata']['HTTPStatusCode'] == 200,\ 'HTTP Status Code %d' % resp['ResponseMetadata']['HTTPStatusCode'] print('Sleeping to let email be stored on s3..') sleep(3) feedback_content = _get_latest_feedback_email_content() key, dt_feedback = _get_latest_email_keys('feedback', w_dt=True)[-1] assert dt_sent_email < dt_feedback assert 'Content-Description: Delivery Status Notification'\ in feedback_content assert html_body_rn in feedback_content # Test if we have the correct email assert resp['MessageId'] in feedback_content assert notifications_return_default in feedback_content assert 'Emmaa email nosetest' in feedback_content
def test_complaint(): # Simulates the recipient's email provider accepting the email and # delivering it to the recipient's inbox, but the recipient marks it as # spam. Amazon SES forwards the complaint notification to you. address = '*****@*****.**' assert not close_to_quota_max(), 'Too close to max send quota' resp = _run_mailbox_simulator(address) dt_sent_email = datetime.utcnow().replace(tzinfo=timezone.utc) assert resp['ResponseMetadata']['HTTPStatusCode'] == 200,\ 'HTTP Status Code %d' % resp['ResponseMetadata']['HTTPStatusCode'] print('Sleeping to let email be stored on s3..') sleep(3) feedback_content = _get_latest_feedback_email_content() key, dt_feedback = _get_latest_email_keys('feedback', w_dt=True)[-1] assert dt_sent_email < dt_feedback # assert 'Content-Description: Delivery Status Notification'\ # in feedback_content assert html_body_rn in feedback_content # Test if we have the correct email assert resp['MessageId'] in feedback_content assert notifications_return_default in feedback_content assert 'Emmaa email nosetest' in feedback_content