mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
update research mode email callbacks to add process-ses-response task to queue
this involved: * moving that task to callback_tasks to prevent circular imports * updating the dummy research mode callbacks (with actual SNS messages from the ses simulator emails) * refactoring tests
This commit is contained in:
@@ -6,7 +6,7 @@ from freezegun import freeze_time
|
||||
|
||||
from app import statsd_client
|
||||
from app.dao.notifications_dao import get_notification_by_id
|
||||
from app.notifications.notifications_ses_callback import process_ses_response
|
||||
from app.notifications.notifications_ses_callback import process_ses_response, remove_emails_from_bounce
|
||||
from tests.app.conftest import sample_notification as create_sample_notification
|
||||
|
||||
|
||||
@@ -180,6 +180,27 @@ def test_ses_callback_should_set_status_to_permanent_failure(client,
|
||||
stats_mock.assert_called_once_with(notification)
|
||||
|
||||
|
||||
def test_remove_emails_from_bounce():
|
||||
# an actual bouncedict example
|
||||
message_dict = {
|
||||
'feedbackId': '0102015fc9acfc14-12341234-1234-1234-1234-123412341234-000000',
|
||||
'bounceType': 'Permanent',
|
||||
'reportingMTA': 'dsn; a1-23.smtp-out.eu-west-4.amazonses.com',
|
||||
'remoteMtaIp': '123.123.123.123',
|
||||
'bounceSubType': 'General',
|
||||
'bouncedRecipients': [{
|
||||
'diagnosticCode': "smtp; 550-5.1.1 The email account that you tried to reach does not exist. Please try\n550-5.1.1 double-checking the recipient's email address for typos or\n550-5.1.1 unnecessary spaces. Learn more at\n550 5.1.1 https://support.google.com/mail/?p=NoSuchUser x33si3064453edx.66 - gsmtp", # noqa
|
||||
'action': 'failed',
|
||||
'status': '5.1.1',
|
||||
'emailAddress': 'not-real@gmail.com'}],
|
||||
'timestamp': '2017-11-17T11:11:18.098Z'
|
||||
}
|
||||
|
||||
remove_emails_from_bounce(message_dict['bounce'])
|
||||
|
||||
assert 'not-real@gmail.com' not in json.dumps(message_dict)
|
||||
|
||||
|
||||
def ses_notification_callback(ref='ref'):
|
||||
return str.encode(
|
||||
'{\n "Type" : "Notification",\n "MessageId" : "%(ref)s",\n "TopicArn" : "arn:aws:sns:eu-west-1:123456789012:testing",\n "Message" : "{\\"notificationType\\":\\"Delivery\\",\\"mail\\":{\\"timestamp\\":\\"2016-03-14T12:35:25.909Z\\",\\"source\\":\\"test@test-domain.com\\",\\"sourceArn\\":\\"arn:aws:ses:eu-west-1:123456789012:identity/testing-notify\\",\\"sendingAccountId\\":\\"123456789012\\",\\"messageId\\":\\"%(ref)s\\",\\"destination\\":[\\"testing@digital.cabinet-office.gov.uk\\"]},\\"delivery\\":{\\"timestamp\\":\\"2016-03-14T12:35:26.567Z\\",\\"processingTimeMillis\\":658,\\"recipients\\":[\\"testing@digital.cabinet-office.gov.uk\\"],\\"smtpResponse\\":\\"250 2.0.0 OK 1457958926 uo5si26480932wjc.221 - gsmtp\\",\\"reportingMTA\\":\\"a6-238.smtp-out.eu-west-1.amazonses.com\\"}}",\n "Timestamp" : "2016-03-14T12:35:26.665Z",\n "SignatureVersion" : "1",\n "Signature" : "X8d7eTAOZ6wlnrdVVPYanrAlsX0SMPfOzhoTEBnQqYkrNWTqQY91C0f3bxtPdUhUtOowyPAOkTQ4KnZuzphfhVb2p1MyVYMxNKcBFB05/qaCX99+92fjw4x9LeUOwyGwMv5F0Vkfi5qZCcEw69uVrhYLVSTFTrzi/yCtru+yFULMQ6UhbY09GwiP6hjxZMVr8aROQy5lLHglqQzOuSZ4KeD85JjifHdKzlx8jjQ+uj+FLzHXPMAPmPU1JK9kpoHZ1oPshAFgPDpphJe+HwcJ8ezmk+3AEUr3wWli3xF+49y8Z2anASSVp6YI2YP95UT8Rlh3qT3T+V9V8rbSVislxA==",\n "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem",\n "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:302763885840:preview-emails:d6aad3ef-83d6-4cf3-a470-54e2e75916da"\n}' % {'ref': ref} # noqa
|
||||
|
||||
Reference in New Issue
Block a user