Added delivery status to services for letter callbacks

This commit is contained in:
venusbb
2017-12-01 21:59:46 +00:00
parent 096657799c
commit f5a0ca9184
2 changed files with 21 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ from app import (
)
from app.aws import s3
from app.celery import provider_tasks
from app.celery.service_callback_tasks import send_delivery_status_to_service
from app.config import QueueNames
from app.dao.inbound_sms_dao import dao_get_inbound_sms_by_id
from app.dao.jobs_dao import (
@@ -42,7 +43,8 @@ from app.dao.notifications_dao import (
get_notification_by_id,
dao_update_notifications_for_job_to_sent_to_dvla,
dao_update_notifications_by_reference,
dao_get_last_notification_added_for_job_id
dao_get_last_notification_added_for_job_id,
dao_get_notifications_by_reference
)
from app.dao.provider_details_dao import get_current_provider
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
@@ -391,6 +393,9 @@ def update_letter_notifications_to_error(self, notification_references):
)
current_app.logger.info("Updated {} letter notifications to technical-failure".format(updated_count))
notifications = dao_get_notifications_by_reference(references=notification_references)
for notification in notifications:
send_delivery_status_to_service.apply_async([notification.id], queue=QueueNames.NOTIFY)
def create_dvla_file_contents_for_job(job_id):
@@ -455,7 +460,7 @@ def update_letter_notifications_statuses(self, filename):
for update in notification_updates:
status = NOTIFICATION_DELIVERED if update.status == DVLA_RESPONSE_STATUS_SENT \
else NOTIFICATION_TECHNICAL_FAILURE
notification = dao_update_notifications_by_reference(
updated_count = dao_update_notifications_by_reference(
references=[update.reference],
update_dict={"status": status,
"billable_units": update.page_count,
@@ -463,7 +468,7 @@ def update_letter_notifications_statuses(self, filename):
}
)
if not notification:
if not updated_count:
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)
@@ -472,6 +477,9 @@ def update_letter_notifications_statuses(self, filename):
current_app.logger.info(
'DVLA file: {filename}, notification updated to {status}: {reference}'.format(
filename=filename, status=status, reference=str(update.reference)))
notifications = dao_get_notifications_by_reference(references=[update.reference])
for notification in notifications:
send_delivery_status_to_service.apply_async([notification.id], queue=QueueNames.NOTIFY)
def process_updates_from_file(response_file):

View File

@@ -101,6 +101,9 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
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)
send_mock = mocker.patch(
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
)
update_letter_notifications_statuses(filename='foo.txt')
@@ -110,6 +113,7 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
assert failed_letter.status == NOTIFICATION_TECHNICAL_FAILURE
assert failed_letter.billable_units == 2
assert failed_letter.updated_at
assert send_mock.called
def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notification_references(
@@ -132,8 +136,12 @@ def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notificati
def test_update_letter_notifications_to_error_updates_based_on_notification_references(
client,
sample_letter_template
sample_letter_template,
mocker
):
send_mock = mocker.patch(
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
)
first = create_notification(sample_letter_template, reference='first ref')
second = create_notification(sample_letter_template, reference='second ref')
@@ -146,3 +154,4 @@ def test_update_letter_notifications_to_error_updates_based_on_notification_refe
assert first.sent_at is None
assert first.updated_at == dt
assert second.status == NOTIFICATION_CREATED
assert send_mock.called