Refactor and add filename in logging

This commit is contained in:
Imdad Ahad
2017-05-12 14:24:17 +01:00
parent 95aa5680f9
commit 0f7093fc38
2 changed files with 2 additions and 6 deletions

View File

@@ -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:

View File

@@ -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'):