From 0f7093fc386f23ed450864e9c384b8b8058d2d03 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 12 May 2017 14:24:17 +0100 Subject: [PATCH] Refactor and add filename in logging --- app/celery/tasks.py | 7 ++----- tests/app/celery/test_tasks.py | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 988977fcd..da90ba6f0 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -365,16 +365,13 @@ def get_template_class(template_type): def update_letter_notifications_statuses(self, filename): bucket_location = '{}-ftp'.format(current_app.config['NOTIFY_EMAIL_DOMAIN']) response_file = s3.get_s3_object(bucket_location, filename).decode('utf-8') - lines = response_file.splitlines() - notification_updates = [] try: NotificationUpdate = namedtuple('NotificationUpdate', ['reference', 'status', 'page_count', 'cost_threshold']) - for line in lines: - notification_updates.append(NotificationUpdate(*line.split('|'))) + notification_updates = [NotificationUpdate(*line.split('|')) for line in response_file.splitlines()] 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 else: diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 12f558f7a..e48932302 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -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): - invalid_file = b'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2' s3_mock = mocker.patch('app.celery.tasks.s3.get_s3_object') with set_config(notify_api, 'NOTIFY_EMAIL_DOMAIN', 'foo.bar'):