Fix a typo error on task argument

Modify unit test to be more robust
This commit is contained in:
venusbb
2018-01-17 12:21:56 +00:00
parent 63bff9d9c3
commit 9179802717
3 changed files with 18 additions and 8 deletions

View File

@@ -119,8 +119,12 @@ 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']: try:
key = obj['Key'].lower() for obj in page['Contents']:
if key.endswith(suffix.lower()): key = obj['Key'].lower()
if not last_modified or obj['LastModified'] >= last_modified: if key.endswith(suffix.lower()):
yield key if not last_modified or obj['LastModified'] >= last_modified:
yield key
except KeyError:
# Not content for today
pass

View File

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

View File

@@ -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,13 @@ 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='test-letters-pdf', subfolder=subfoldername, suffix='.zip'),
call(bucket_name='test.notify.com-ftp', subfolder='root/dispatch', suffix='.ACK.txt', last_modified=yesterday),
]
assert mock_get_file.call_count == 1 assert mock_get_file.call_count == 1