Update to pull from correct bucket and fix tests not mocking out correctly

This commit is contained in:
Imdad Ahad
2017-05-04 11:42:59 +01:00
parent 20bb91bfdd
commit 8a5e82904e
3 changed files with 18 additions and 5 deletions

View File

@@ -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 = []

View File

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

View File

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