mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Refactor and add filename in logging
This commit is contained in:
@@ -365,16 +365,13 @@ def get_template_class(template_type):
|
|||||||
def update_letter_notifications_statuses(self, filename):
|
def update_letter_notifications_statuses(self, filename):
|
||||||
bucket_location = '{}-ftp'.format(current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
bucket_location = '{}-ftp'.format(current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||||
response_file = s3.get_s3_object(bucket_location, filename).decode('utf-8')
|
response_file = s3.get_s3_object(bucket_location, filename).decode('utf-8')
|
||||||
lines = response_file.splitlines()
|
|
||||||
notification_updates = []
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
NotificationUpdate = namedtuple('NotificationUpdate', ['reference', 'status', 'page_count', 'cost_threshold'])
|
NotificationUpdate = namedtuple('NotificationUpdate', ['reference', 'status', 'page_count', 'cost_threshold'])
|
||||||
for line in lines:
|
notification_updates = [NotificationUpdate(*line.split('|')) for line in response_file.splitlines()]
|
||||||
notification_updates.append(NotificationUpdate(*line.split('|')))
|
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
current_app.logger.exception('DVLA response file has an invalid format')
|
current_app.logger.exception('DVLA response file: {} has an invalid format'.format(filename))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1087,7 +1087,6 @@ def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_a
|
|||||||
|
|
||||||
|
|
||||||
def test_update_letter_notifications_statuses_calls_with_correct_bucket_location(notify_api, mocker):
|
def test_update_letter_notifications_statuses_calls_with_correct_bucket_location(notify_api, mocker):
|
||||||
invalid_file = b'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2'
|
|
||||||
s3_mock = mocker.patch('app.celery.tasks.s3.get_s3_object')
|
s3_mock = mocker.patch('app.celery.tasks.s3.get_s3_object')
|
||||||
|
|
||||||
with set_config(notify_api, 'NOTIFY_EMAIL_DOMAIN', 'foo.bar'):
|
with set_config(notify_api, 'NOTIFY_EMAIL_DOMAIN', 'foo.bar'):
|
||||||
|
|||||||
Reference in New Issue
Block a user