mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Update to pull from correct bucket and fix tests not mocking out correctly
This commit is contained in:
@@ -363,7 +363,8 @@ def get_template_class(template_type):
|
|||||||
@notify_celery.task(bind=True, name='update-letter-notifications-statuses')
|
@notify_celery.task(bind=True, name='update-letter-notifications-statuses')
|
||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
def update_letter_notifications_statuses(self, filename):
|
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()
|
lines = response_file.splitlines()
|
||||||
notification_updates = []
|
notification_updates = []
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ from app.models import (
|
|||||||
Job)
|
Job)
|
||||||
|
|
||||||
from tests.app import load_example_csv
|
from tests.app import load_example_csv
|
||||||
|
from tests.conftest import set_config
|
||||||
from tests.app.conftest import (
|
from tests.app.conftest import (
|
||||||
sample_service,
|
sample_service,
|
||||||
sample_template,
|
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')
|
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):
|
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'
|
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)
|
mocker.patch('app.celery.tasks.s3.get_s3_object', return_value=valid_file)
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ def test_dvla_callback_returns_400_with_invalid_request(client):
|
|||||||
assert json_resp['message'] == 'DVLA callback failed: Invalid JSON'
|
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()
|
data = _sample_sns_s3_callback()
|
||||||
|
mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses.apply_async')
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/notifications/letter/dvla',
|
path='/notifications/letter/dvla',
|
||||||
data=data,
|
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):
|
def test_dvla_callback_calls_update_letter_notifications_task(client, mocker):
|
||||||
update_notifications_mock = \
|
update_task = \
|
||||||
mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses')
|
mocker.patch('app.notifications.notifications_letter_callback.update_letter_notifications_statuses.apply_async')
|
||||||
data = _sample_sns_s3_callback()
|
data = _sample_sns_s3_callback()
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/notifications/letter/dvla',
|
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))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
|
||||||
assert response.status_code == 200
|
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):
|
def test_firetext_callback_should_not_need_auth(client, mocker):
|
||||||
|
|||||||
Reference in New Issue
Block a user