mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Add some useful information to the log.
Fix unit test to actually test the right thing
This commit is contained in:
@@ -95,8 +95,8 @@ def process_ses_response(ses_request):
|
|||||||
|
|
||||||
|
|
||||||
def determine_notification_bounce_type(notification_type, ses_message):
|
def determine_notification_bounce_type(notification_type, ses_message):
|
||||||
remove_emails_from_bounce(ses_message['bounce'])
|
remove_emails_from_bounce(ses_message)
|
||||||
current_app.logger.info('SES bounce dict: {}'.format(ses_message['bounce']))
|
current_app.logger.info('SES bounce dict: {}'.format(ses_message))
|
||||||
if ses_message['bounce']['bounceType'] == 'Permanent':
|
if ses_message['bounce']['bounceType'] == 'Permanent':
|
||||||
notification_type = ses_message['bounce']['bounceType'] # permanent or not
|
notification_type = ses_message['bounce']['bounceType'] # permanent or not
|
||||||
else:
|
else:
|
||||||
@@ -105,8 +105,12 @@ def determine_notification_bounce_type(notification_type, ses_message):
|
|||||||
|
|
||||||
|
|
||||||
def remove_emails_from_bounce(bounce_dict):
|
def remove_emails_from_bounce(bounce_dict):
|
||||||
for recip in bounce_dict['bouncedRecipients']:
|
if bounce_dict.get('mail').get('headers', None):
|
||||||
recip.pop('emailAddress')
|
bounce_dict['mail'].pop('headers')
|
||||||
|
if bounce_dict.get('mail').get('commonHeaders'):
|
||||||
|
bounce_dict['mail'].pop('commonHeaders')
|
||||||
|
bounce_dict['mail'].pop('destination')
|
||||||
|
bounce_dict['bounce'].pop('bouncedRecipients')
|
||||||
|
|
||||||
|
|
||||||
def handle_complaint(ses_message):
|
def handle_complaint(ses_message):
|
||||||
@@ -131,6 +135,10 @@ def handle_complaint(ses_message):
|
|||||||
|
|
||||||
|
|
||||||
def remove_emails_from_complaint(complaint_dict):
|
def remove_emails_from_complaint(complaint_dict):
|
||||||
|
if complaint_dict.get('headers', None):
|
||||||
|
complaint_dict.pop('headers')
|
||||||
|
if complaint_dict.get('commonHeaders'):
|
||||||
|
complaint_dict.pop('commonHeaders')
|
||||||
complaint_dict['complaint'].pop('complainedRecipients')
|
complaint_dict['complaint'].pop('complainedRecipients')
|
||||||
complaint_dict['mail'].pop('destination')
|
complaint_dict['mail'].pop('destination')
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import json
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from app.celery.process_ses_receipts_tasks import process_ses_results
|
from app.celery.process_ses_receipts_tasks import process_ses_results
|
||||||
|
from app.celery.research_mode_tasks import ses_hard_bounce_callback
|
||||||
from app.models import Complaint
|
from app.models import Complaint
|
||||||
from app.notifications.notifications_ses_callback import remove_emails_from_complaint
|
from app.notifications.notifications_ses_callback import remove_emails_from_complaint, remove_emails_from_bounce
|
||||||
|
|
||||||
from tests.app.db import (
|
from tests.app.db import (
|
||||||
create_notification, ses_complaint_callback,
|
create_notification, ses_complaint_callback,
|
||||||
@@ -51,3 +52,9 @@ def test_remove_emails_from_complaint():
|
|||||||
test_json = json.loads(ses_complaint_callback()['Message'])
|
test_json = json.loads(ses_complaint_callback()['Message'])
|
||||||
remove_emails_from_complaint(test_json)
|
remove_emails_from_complaint(test_json)
|
||||||
assert "recipient1@example.com" not in json.dumps(test_json)
|
assert "recipient1@example.com" not in json.dumps(test_json)
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_email_from_bounce():
|
||||||
|
test_json = json.loads(ses_hard_bounce_callback(reference='ref1')['Message'])
|
||||||
|
remove_emails_from_bounce(test_json)
|
||||||
|
assert "bounce@simulator.amazonses.com" not in json.dumps(test_json)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from app import statsd_client
|
|||||||
from app.dao.notifications_dao import get_notification_by_id
|
from app.dao.notifications_dao import get_notification_by_id
|
||||||
from app.models import Notification, Complaint
|
from app.models import Notification, Complaint
|
||||||
from app.notifications.notifications_ses_callback import (
|
from app.notifications.notifications_ses_callback import (
|
||||||
process_ses_response, remove_emails_from_bounce,
|
process_ses_response,
|
||||||
handle_complaint
|
handle_complaint
|
||||||
)
|
)
|
||||||
from app.celery.research_mode_tasks import ses_hard_bounce_callback, ses_soft_bounce_callback, ses_notification_callback
|
from app.celery.research_mode_tasks import ses_hard_bounce_callback, ses_soft_bounce_callback, ses_notification_callback
|
||||||
@@ -192,15 +192,6 @@ def test_ses_callback_should_set_status_to_permanent_failure(client,
|
|||||||
assert send_mock.called
|
assert send_mock.called
|
||||||
|
|
||||||
|
|
||||||
def test_remove_emails_from_bounce():
|
|
||||||
# an actual bouncedict example
|
|
||||||
message_dict = json.loads(ses_hard_bounce_callback(reference='ref')['Message'])
|
|
||||||
|
|
||||||
remove_emails_from_bounce(message_dict['bounce'])
|
|
||||||
|
|
||||||
assert 'not-real@gmail.com' not in json.dumps(message_dict)
|
|
||||||
|
|
||||||
|
|
||||||
def test_process_ses_results_in_complaint(sample_email_template):
|
def test_process_ses_results_in_complaint(sample_email_template):
|
||||||
notification = create_notification(template=sample_email_template, reference='ref1')
|
notification = create_notification(template=sample_email_template, reference='ref1')
|
||||||
handle_complaint(json.loads(ses_complaint_callback()['Message']))
|
handle_complaint(json.loads(ses_complaint_callback()['Message']))
|
||||||
|
|||||||
Reference in New Issue
Block a user