Add get_s3_file method for use in DVLA processing

This commit is contained in:
Imdad Ahad
2017-05-12 17:39:15 +01:00
parent cd85550889
commit ee484ec368
4 changed files with 78 additions and 3 deletions

11
tests/app/aws/test_s3.py Normal file
View File

@@ -0,0 +1,11 @@
from app.aws.s3 import get_s3_file
def test_get_s3_file_makes_correct_call(sample_service, sample_job, mocker):
get_s3_mock = mocker.patch('app.aws.s3.get_s3_object')
get_s3_file('foo-bucket', 'bar-file.txt')
get_s3_mock.assert_called_with(
'foo-bucket',
'bar-file.txt'
)

View File

@@ -1071,3 +1071,37 @@ def test_update_dvla_job_to_error(sample_letter_template, sample_letter_job):
assert not n.sent_by
assert 'error' == Job.query.filter_by(id=sample_letter_job.id).one().job_status
def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_api, mocker):
invalid_file = 'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2'
mocker.patch('app.celery.tasks.s3.get_s3_file', return_value=invalid_file)
with pytest.raises(TypeError):
update_letter_notifications_statuses(filename='foo.txt')
def test_update_letter_notifications_statuses_calls_with_correct_bucket_location(notify_api, mocker):
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 = 'ref-foo|Sent|1|Unsorted\nref-bar|Sent|2|Sorted'
mocker.patch('app.celery.tasks.s3.get_s3_file', return_value=valid_file)
updates = update_letter_notifications_statuses(filename='foo.txt')
assert len(updates) == 2
assert updates[0].reference == 'ref-foo'
assert updates[0].status == 'Sent'
assert updates[0].page_count == '1'
assert updates[0].cost_threshold == 'Unsorted'
assert updates[1].reference == 'ref-bar'
assert updates[1].status == 'Sent'
assert updates[1].page_count == '2'
assert updates[1].cost_threshold == 'Sorted'