When a notification is timed out in the scheduled task that may happen because the notification has not been sent.

Which means the sent_at date for the notification could be empty causing the service callback to fail.

- Allow code to work if notification.sent_at or updated_at is None
- Update calls to send_delivery_status_to_service to send the data encrypted so that the task does not need to use the db.
This commit is contained in:
Rebecca Law
2018-03-16 14:00:49 +00:00
parent 5db110bb3f
commit c9477a7400
8 changed files with 88 additions and 20 deletions

View File

@@ -57,6 +57,7 @@ from app.models import (
SMS_TYPE
)
from app.utils import get_london_midnight_in_utc
from app.celery.service_callback_tasks import create_encrypted_callback_data
from app.v2.errors import JobIncompleteError
from tests.app.db import (
create_notification, create_service, create_template, create_job, create_rate,
@@ -210,7 +211,7 @@ def test_should_not_update_status_of_letter_notifications(client, sample_letter_
def test_timeout_notifications_sends_status_update_to_service(client, sample_template, mocker):
create_service_callback_api(service=sample_template.service)
callback_api = create_service_callback_api(service=sample_template.service)
mocked = mocker.patch('app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async')
notification = create_notification(
template=sample_template,
@@ -218,7 +219,9 @@ def test_timeout_notifications_sends_status_update_to_service(client, sample_tem
created_at=datetime.utcnow() - timedelta(
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD') + 10))
timeout_notifications()
mocked.assert_called_once_with([str(notification.id)], queue=QueueNames.CALLBACKS)
encrypted_data = create_encrypted_callback_data(notification, callback_api)
mocked.assert_called_once_with([str(notification.id), encrypted_data], queue=QueueNames.CALLBACKS)
def test_should_update_scheduled_jobs_and_put_on_queue(notify_db, notify_db_session, mocker):