mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 02:23:32 -04:00
Use set rather than list to compare ack file and zip files difference
This commit is contained in:
@@ -487,36 +487,32 @@ def daily_stats_template_usage_by_month():
|
|||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
def letter_raise_alert_if_no_ack_file_for_zip():
|
def letter_raise_alert_if_no_ack_file_for_zip():
|
||||||
# get a list of zip files since yesterday
|
# get a list of zip files since yesterday
|
||||||
zip_file_list = []
|
zip_file_set = set()
|
||||||
|
|
||||||
for key in s3.get_list_of_files_by_suffix(bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'],
|
for key in s3.get_list_of_files_by_suffix(bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'],
|
||||||
subfolder=datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
|
subfolder=datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
|
||||||
suffix='.TXT'):
|
suffix='.TXT'):
|
||||||
zip_file_list.append(key.upper().rstrip('.TXT'))
|
zip_file_set.add(key.upper().rstrip('.TXT'))
|
||||||
|
|
||||||
# get acknowledgement file
|
# get acknowledgement file
|
||||||
ack_file_list = []
|
ack_file_set = set()
|
||||||
# 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', last_modified=yesterday):
|
subfolder='root/dispatch', suffix='.ACK.txt', last_modified=yesterday):
|
||||||
ack_file_list.append(key)
|
ack_file_set.add(key)
|
||||||
|
|
||||||
today_str = datetime.utcnow().strftime('%Y%m%d')
|
today_str = datetime.utcnow().strftime('%Y%m%d')
|
||||||
zip_not_today = []
|
|
||||||
|
|
||||||
for key in ack_file_list:
|
ack_content_set = set()
|
||||||
|
for key in ack_file_set:
|
||||||
if today_str in key:
|
if today_str in key:
|
||||||
content = s3.get_s3_file(current_app.config['DVLA_RESPONSE_BUCKET_NAME'], key)
|
content = s3.get_s3_file(current_app.config['DVLA_RESPONSE_BUCKET_NAME'], key)
|
||||||
for zip_file in content.split('\n'): # each line
|
for zip_file in content.split('\n'): # each line
|
||||||
s = zip_file.split('|')
|
s = zip_file.split('|')
|
||||||
for zf in zip_file_list:
|
ack_content_set.add(s[0].upper())
|
||||||
if s[0].upper() in zf:
|
|
||||||
zip_file_list.remove(zf)
|
|
||||||
else:
|
|
||||||
zip_not_today.append(s[0])
|
|
||||||
|
|
||||||
if zip_file_list:
|
if len(zip_file_set - ack_content_set) > 0:
|
||||||
deskpro_client.create_ticket(
|
deskpro_client.create_ticket(
|
||||||
subject="Letter acknowledge error",
|
subject="Letter acknowledge error",
|
||||||
message="Letter acknowledgement file do not contains all zip files sent: {}".format(datetime.utcnow()
|
message="Letter acknowledgement file do not contains all zip files sent: {}".format(datetime.utcnow()
|
||||||
@@ -524,9 +520,9 @@ def letter_raise_alert_if_no_ack_file_for_zip():
|
|||||||
ticket_type='alert'
|
ticket_type='alert'
|
||||||
)
|
)
|
||||||
|
|
||||||
raise NoAckFileReceived(message=zip_file_list)
|
raise NoAckFileReceived(message=str(zip_file_set - ack_content_set))
|
||||||
|
|
||||||
if zip_not_today:
|
if len(ack_content_set - zip_file_set) > 0:
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
"letter ack contains zip that is not for today {} ".format(zip_not_today)
|
"letter ack contains zip that is not for today: {}".format(ack_content_set - zip_file_set)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1154,7 +1154,7 @@ def test_letter_not_raise_alert_if_ack_files_not_match_zip_list(mocker, notify_d
|
|||||||
with pytest.raises(expected_exception=NoAckFileReceived) as e:
|
with pytest.raises(expected_exception=NoAckFileReceived) as e:
|
||||||
letter_raise_alert_if_no_ack_file_for_zip()
|
letter_raise_alert_if_no_ack_file_for_zip()
|
||||||
|
|
||||||
assert e.value.message == ['NOTIFY.20180111175009.ZIP', 'NOTIFY.20180111175010.ZIP']
|
assert e.value.message == str(set(['NOTIFY.20180111175009.ZIP', 'NOTIFY.20180111175010.ZIP']))
|
||||||
assert mock_file_list.call_count == 2
|
assert mock_file_list.call_count == 2
|
||||||
assert mock_get_file.call_count == 1
|
assert mock_get_file.call_count == 1
|
||||||
mock_deskpro.assert_called_once_with(
|
mock_deskpro.assert_called_once_with(
|
||||||
|
|||||||
Reference in New Issue
Block a user