mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Using key query rather than try catch
Added a unit test for empty content
This commit is contained in:
@@ -119,12 +119,8 @@ def get_list_of_files_by_suffix(bucket_name, subfolder='', suffix='', last_modif
|
||||
)
|
||||
|
||||
for page in page_iterator:
|
||||
try:
|
||||
for obj in page['Contents']:
|
||||
for obj in page.get('Contents', []):
|
||||
key = obj['Key'].lower()
|
||||
if key.endswith(suffix.lower()):
|
||||
if not last_modified or obj['LastModified'] >= last_modified:
|
||||
yield key
|
||||
except KeyError:
|
||||
# Not content for today
|
||||
pass
|
||||
|
||||
@@ -208,3 +208,18 @@ def test_get_list_of_files_by_suffix(notify_api, mocker, suffix_str, days_before
|
||||
assert sum(1 for x in key) == returned_no
|
||||
for k in key:
|
||||
assert k == 'bar/foo.ACK.txt'
|
||||
|
||||
|
||||
def test_get_list_of_files_by_suffix_empty_contents_return_with_no_error(notify_api, mocker):
|
||||
paginator_mock = mocker.patch('app.aws.s3.client')
|
||||
multiple_pages_s3_object = [
|
||||
{
|
||||
"other_content": [
|
||||
'some_values',
|
||||
]
|
||||
}
|
||||
]
|
||||
paginator_mock.return_value.get_paginator.return_value.paginate.return_value = multiple_pages_s3_object
|
||||
key = get_list_of_files_by_suffix('foo-bucket', subfolder='bar', suffix='.pdf')
|
||||
|
||||
assert sum(1 for x in key) == 0
|
||||
|
||||
@@ -1058,8 +1058,9 @@ def test_letter_not_raise_alert_if_ack_files_match_zip_list(mocker, notify_db):
|
||||
subfoldername = datetime.utcnow().strftime('%Y-%m-%d')
|
||||
assert mock_file_list.call_count == 2
|
||||
assert mock_file_list.call_args_list == [
|
||||
call(bucket_name='test-letters-pdf', subfolder=subfoldername, suffix='.zip'),
|
||||
call(bucket_name='test.notify.com-ftp', subfolder='root/dispatch', suffix='.ACK.txt', last_modified=yesterday),
|
||||
call(bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'], subfolder=subfoldername, suffix='.zip'),
|
||||
call(bucket_name=current_app.config['DVLA_RESPONSE_BUCKET_NAME'], subfolder='root/dispatch',
|
||||
suffix='.ACK.txt', last_modified=yesterday),
|
||||
]
|
||||
assert mock_get_file.call_count == 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user