mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Update letter noti status based on dvla response file
This commit is contained in:
@@ -36,6 +36,7 @@ from app.dao.jobs_dao import (
|
|||||||
dao_update_job_status)
|
dao_update_job_status)
|
||||||
from app.dao.notifications_dao import (
|
from app.dao.notifications_dao import (
|
||||||
get_notification_by_id,
|
get_notification_by_id,
|
||||||
|
update_notification_status_by_reference,
|
||||||
dao_update_notifications_for_job_to_sent_to_dvla,
|
dao_update_notifications_for_job_to_sent_to_dvla,
|
||||||
dao_update_notifications_by_reference,
|
dao_update_notifications_by_reference,
|
||||||
dao_get_last_notification_added_for_job_id)
|
dao_get_last_notification_added_for_job_id)
|
||||||
@@ -46,6 +47,7 @@ from app.dao.templates_dao import dao_get_template_by_id
|
|||||||
from app.models import (
|
from app.models import (
|
||||||
Job,
|
Job,
|
||||||
Notification,
|
Notification,
|
||||||
|
DVLA_STATUS_SENT,
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
JOB_STATUS_CANCELLED,
|
JOB_STATUS_CANCELLED,
|
||||||
JOB_STATUS_FINISHED,
|
JOB_STATUS_FINISHED,
|
||||||
@@ -55,6 +57,8 @@ from app.models import (
|
|||||||
JOB_STATUS_SENT_TO_DVLA, JOB_STATUS_ERROR,
|
JOB_STATUS_SENT_TO_DVLA, JOB_STATUS_ERROR,
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
|
NOTIFICATION_DELIVERED,
|
||||||
|
NOTIFICATION_FAILED,
|
||||||
NOTIFICATION_SENDING,
|
NOTIFICATION_SENDING,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
NOTIFICATION_TECHNICAL_FAILURE,
|
||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
@@ -443,8 +447,21 @@ def update_letter_notifications_statuses(self, filename):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
for update in notification_updates:
|
for update in notification_updates:
|
||||||
current_app.logger.info('DVLA update: {}'.format(str(update)))
|
status = NOTIFICATION_DELIVERED if update.status == DVLA_STATUS_SENT else NOTIFICATION_FAILED
|
||||||
# TODO: Update notifications with desired status
|
notification = update_notification_status_by_reference(
|
||||||
|
update.reference,
|
||||||
|
status
|
||||||
|
)
|
||||||
|
|
||||||
|
if not notification:
|
||||||
|
msg = "Update letter notification file {filename} failed: notification either not found " \
|
||||||
|
"or already updated from delivered. Status {status} for notification reference {reference}".format(
|
||||||
|
filename=filename, status=status, reference=update.reference)
|
||||||
|
current_app.logger.error(msg)
|
||||||
|
else:
|
||||||
|
current_app.logger.info(
|
||||||
|
'DVLA file: {filename}, notification updated to {status}: {reference}'.format(
|
||||||
|
filename=filename, status=status, reference=str(update.reference)))
|
||||||
|
|
||||||
|
|
||||||
def process_updates_from_file(response_file):
|
def process_updates_from_file(response_file):
|
||||||
|
|||||||
@@ -7,10 +7,14 @@ from flask import current_app
|
|||||||
from app.models import (
|
from app.models import (
|
||||||
Job,
|
Job,
|
||||||
Notification,
|
Notification,
|
||||||
|
NOTIFICATION_DELIVERED,
|
||||||
|
NOTIFICATION_FAILED,
|
||||||
NOTIFICATION_SENDING,
|
NOTIFICATION_SENDING,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE
|
NOTIFICATION_TECHNICAL_FAILURE,
|
||||||
|
NOTIFICATION_STATUS_LETTER_RECEIVED
|
||||||
)
|
)
|
||||||
|
from app.dao.notifications_dao import dao_update_notifications_by_reference
|
||||||
from app.celery.tasks import (
|
from app.celery.tasks import (
|
||||||
update_job_to_sent_to_dvla,
|
update_job_to_sent_to_dvla,
|
||||||
update_dvla_job_to_error,
|
update_dvla_job_to_error,
|
||||||
@@ -91,6 +95,20 @@ def test_update_letter_notifications_statuses_builds_updates_list(notify_api, mo
|
|||||||
assert updates[1].cost_threshold == 'Sorted'
|
assert updates[1].cost_threshold == 'Sorted'
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_letter_notifications_statuses_persisted(notify_api, mocker, sample_letter_template):
|
||||||
|
sent_letter = create_notification(sample_letter_template, reference='ref-foo', status=NOTIFICATION_SENDING)
|
||||||
|
failed_letter = create_notification(sample_letter_template, reference='ref-bar', status=NOTIFICATION_SENDING)
|
||||||
|
|
||||||
|
valid_file = '{}|Sent|1|Unsorted\n{}|Failed|2|Sorted'.format(
|
||||||
|
sent_letter.reference, failed_letter.reference)
|
||||||
|
mocker.patch('app.celery.tasks.s3.get_s3_file', return_value=valid_file)
|
||||||
|
|
||||||
|
update_letter_notifications_statuses(filename='foo.txt')
|
||||||
|
|
||||||
|
assert sent_letter.status == NOTIFICATION_DELIVERED
|
||||||
|
assert failed_letter.status == NOTIFICATION_FAILED
|
||||||
|
|
||||||
|
|
||||||
def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notification_references(
|
def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notification_references(
|
||||||
client,
|
client,
|
||||||
sample_letter_template
|
sample_letter_template
|
||||||
|
|||||||
Reference in New Issue
Block a user