From 1d30d93c6f1182103a4d9f4e6dc2c6a89a52e968 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Wed, 7 Jun 2017 16:31:14 +0100 Subject: [PATCH] Add s3 method to remove transformed dvla files --- app/aws/s3.py | 7 +++++++ app/v2/notifications/get_notifications.py | 2 +- tests/app/aws/test_s3.py | 20 ++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/aws/s3.py b/app/aws/s3.py index ed206b3a4..f5798314b 100644 --- a/app/aws/s3.py +++ b/app/aws/s3.py @@ -26,3 +26,10 @@ def remove_job_from_s3(service_id, job_id): file_location = FILE_LOCATION_STRUCTURE.format(service_id, job_id) obj = get_s3_object(bucket_name, file_location) return obj.delete() + + +def remove_transformed_dvla_file(job_id): + bucket_name = current_app.config['DVLA_UPLOAD_BUCKET_NAME'] + file_location = '{}-dvla-job.text'.format(job_id) + obj = get_s3_object(bucket_name, file_location) + return obj.delete() diff --git a/app/v2/notifications/get_notifications.py b/app/v2/notifications/get_notifications.py index 08a0d3c5e..cd721f596 100644 --- a/app/v2/notifications/get_notifications.py +++ b/app/v2/notifications/get_notifications.py @@ -14,7 +14,7 @@ from app.v2.notifications.notification_schemas import get_notifications_request def get_notification_by_id(id): try: casted_id = uuid.UUID(id) - except ValueError or AttributeError: + except (ValueError, AttributeError): abort(404) notification = notifications_dao.get_notification_with_personalisation( authenticated_service.id, casted_id, key_type=None diff --git a/tests/app/aws/test_s3.py b/tests/app/aws/test_s3.py index 38c9966dd..fd30c16df 100644 --- a/tests/app/aws/test_s3.py +++ b/tests/app/aws/test_s3.py @@ -1,7 +1,11 @@ -from app.aws.s3 import get_s3_file +from unittest.mock import call + +from flask import current_app + +from app.aws.s3 import get_s3_file, remove_transformed_dvla_file -def test_get_s3_file_makes_correct_call(sample_service, sample_job, mocker): +def test_get_s3_file_makes_correct_call(notify_api, mocker): get_s3_mock = mocker.patch('app.aws.s3.get_s3_object') get_s3_file('foo-bucket', 'bar-file.txt') @@ -9,3 +13,15 @@ def test_get_s3_file_makes_correct_call(sample_service, sample_job, mocker): 'foo-bucket', 'bar-file.txt' ) + + +def test_remove_transformed_dvla_file_makes_correct_call(notify_api, mocker): + s3_mock = mocker.patch('app.aws.s3.get_s3_object') + fake_uuid = '5fbf9799-6b9b-4dbb-9a4e-74a939f3bb49' + + remove_transformed_dvla_file(fake_uuid) + + s3_mock.assert_has_calls([ + call(current_app.config['DVLA_UPLOAD_BUCKET_NAME'], '{}-dvla-job.text'.format(fake_uuid)), + call().delete() + ])