From 8a5e82904e4ffe58bbd6ffcb3696e44db905ec66 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Thu, 4 May 2017 11:42:59 +0100 Subject: [PATCH] Update to pull from correct bucket and fix tests not mocking out correctly --- app/celery/tasks.py | 3 ++- tests/app/celery/test_tasks.py | 10 ++++++++++ tests/app/notifications/rest/test_callbacks.py | 10 ++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 4ebb73a42..8498ff05a 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -363,7 +363,8 @@ def get_template_class(template_type): @notify_celery.task(bind=True, name='update-letter-notifications-statuses') @statsd(namespace="tasks") def update_letter_notifications_statuses(self, filename): - response_file = s3.get_s3_object('development-notifications-csv-upload', filename).decode('utf-8') + 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 = [] diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 4eb74da47..12f558f7a 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -38,6 +38,7 @@ from app.models import ( Job) from tests.app import load_example_csv +from tests.conftest import set_config from tests.app.conftest import ( sample_service, sample_template, @@ -1085,6 +1086,15 @@ def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_a update_letter_notifications_statuses(filename='foo.txt') +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'): + update_letter_notifications_statuses(filename='foo.txt') + s3_mock.assert_called_with('{}-ftp'.format(current_app.config['NOTIFY_EMAIL_DOMAIN']), 'foo.txt') + + def test_update_letter_notifications_statuses_builds_updates_list(notify_api, mocker): valid_file = b'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2|Sorted' mocker.patch('app.celery.tasks.s3.get_s3_object', return_value=valid_file) diff --git a/tests/app/notifications/rest/test_callbacks.py b/tests/app/notifications/rest/test_callbacks.py index 0dd070271..095384836 100644 --- a/tests/app/notifications/rest/test_callbacks.py +++ b/tests/app/notifications/rest/test_callbacks.py @@ -29,8 +29,9 @@ def test_dvla_callback_returns_400_with_invalid_request(client): assert json_resp['message'] == 'DVLA callback failed: Invalid JSON' -def test_dvla_callback_returns_200_with_valid_request(client): +def test_dvla_callback_returns_200_with_valid_request(client, mocker): data = _sample_sns_s3_callback() + mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses.apply_async') response = client.post( path='/notifications/letter/dvla', data=data, @@ -42,8 +43,8 @@ def test_dvla_callback_returns_200_with_valid_request(client): def test_dvla_callback_calls_update_letter_notifications_task(client, mocker): - update_notifications_mock = \ - mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses') + update_task = \ + mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses.apply_async') data = _sample_sns_s3_callback() response = client.post( path='/notifications/letter/dvla', @@ -53,7 +54,8 @@ def test_dvla_callback_calls_update_letter_notifications_task(client, mocker): json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 - assert update_notifications_mock.apply_async.called is True + assert update_task.called is True + update_task.assert_called_with(['bar.txt'], queue='notify') def test_firetext_callback_should_not_need_auth(client, mocker):