mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
Merge pull request #1578 from alphagov/raise-alert-when-no-ack-file
Fix a typo error on task argument
This commit is contained in:
@@ -119,7 +119,7 @@ def get_list_of_files_by_suffix(bucket_name, subfolder='', suffix='', last_modif
|
|||||||
)
|
)
|
||||||
|
|
||||||
for page in page_iterator:
|
for page in page_iterator:
|
||||||
for obj in page['Contents']:
|
for obj in page.get('Contents', []):
|
||||||
key = obj['Key'].lower()
|
key = obj['Key'].lower()
|
||||||
if key.endswith(suffix.lower()):
|
if key.endswith(suffix.lower()):
|
||||||
if not last_modified or obj['LastModified'] >= last_modified:
|
if not last_modified or obj['LastModified'] >= last_modified:
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ def letter_raise_alert_if_no_ack_file_for_zip():
|
|||||||
# yesterday = datetime.now(tz=pytz.utc) - timedelta(days=1)
|
# yesterday = datetime.now(tz=pytz.utc) - timedelta(days=1)
|
||||||
yesterday = datetime.utcnow() - timedelta(days=1)
|
yesterday = datetime.utcnow() - timedelta(days=1)
|
||||||
for key in s3.get_list_of_files_by_suffix(bucket_name=current_app.config['DVLA_RESPONSE_BUCKET_NAME'],
|
for key in s3.get_list_of_files_by_suffix(bucket_name=current_app.config['DVLA_RESPONSE_BUCKET_NAME'],
|
||||||
subfolder='root/dispatch', suffix='.ACK.txt', lastModified=yesterday):
|
subfolder='root/dispatch', suffix='.ACK.txt', last_modified=yesterday):
|
||||||
ack_file_list.append(key)
|
ack_file_list.append(key)
|
||||||
|
|
||||||
today_str = datetime.utcnow().strftime('%Y%m%d')
|
today_str = datetime.utcnow().strftime('%Y%m%d')
|
||||||
|
|||||||
@@ -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
|
assert sum(1 for x in key) == returned_no
|
||||||
for k in key:
|
for k in key:
|
||||||
assert k == 'bar/foo.ACK.txt'
|
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
|
||||||
|
|||||||
@@ -1029,7 +1029,7 @@ def test_dao_fetch_monthly_historical_stats_by_template_null_template_id_not_cou
|
|||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|
||||||
def mock_s3_get_list_match(bucket_name, subfolder='', suffix='', lastModified=None):
|
def mock_s3_get_list_match(bucket_name, subfolder='', suffix='', last_modified=None):
|
||||||
|
|
||||||
if subfolder == '2018-01-11':
|
if subfolder == '2018-01-11':
|
||||||
return ['NOTIFY.20180111175007.ZIP', 'NOTIFY.20180111175008.ZIP']
|
return ['NOTIFY.20180111175007.ZIP', 'NOTIFY.20180111175008.ZIP']
|
||||||
@@ -1037,7 +1037,7 @@ def mock_s3_get_list_match(bucket_name, subfolder='', suffix='', lastModified=No
|
|||||||
return ['root/dispatch/NOTIFY.20180111175733.ACK.txt']
|
return ['root/dispatch/NOTIFY.20180111175733.ACK.txt']
|
||||||
|
|
||||||
|
|
||||||
def mock_s3_get_list_diff(bucket_name, subfolder='', suffix='', lastModified=None):
|
def mock_s3_get_list_diff(bucket_name, subfolder='', suffix='', last_modified=None):
|
||||||
if subfolder == '2018-01-11':
|
if subfolder == '2018-01-11':
|
||||||
return ['NOTIFY.20180111175007.ZIP', 'NOTIFY.20180111175008.ZIP', 'NOTIFY.20180111175009.ZIP',
|
return ['NOTIFY.20180111175007.ZIP', 'NOTIFY.20180111175008.ZIP', 'NOTIFY.20180111175009.ZIP',
|
||||||
'NOTIFY.20180111175010.ZIP']
|
'NOTIFY.20180111175010.ZIP']
|
||||||
@@ -1054,7 +1054,14 @@ def test_letter_not_raise_alert_if_ack_files_match_zip_list(mocker, notify_db):
|
|||||||
|
|
||||||
letter_raise_alert_if_no_ack_file_for_zip()
|
letter_raise_alert_if_no_ack_file_for_zip()
|
||||||
|
|
||||||
|
yesterday = datetime.utcnow() - timedelta(days=1)
|
||||||
|
subfoldername = datetime.utcnow().strftime('%Y-%m-%d')
|
||||||
assert mock_file_list.call_count == 2
|
assert mock_file_list.call_count == 2
|
||||||
|
assert mock_file_list.call_args_list == [
|
||||||
|
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
|
assert mock_get_file.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user