Add scheduled task to send scheduled notifcations.

Fix the query to fetch scheduled notifications.
This commit is contained in:
Rebecca Law
2017-05-16 13:47:22 +01:00
parent 56f657de9b
commit 2e078f9fc8
5 changed files with 55 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ from functools import partial
from flask import current_app
from freezegun import freeze_time
from app.celery.scheduled_tasks import s3
from app.celery.scheduled_tasks import s3, send_scheduled_notifications
from app.celery import scheduled_tasks
from app.celery.scheduled_tasks import (
delete_verify_codes,
@@ -30,8 +30,8 @@ from tests.app.db import create_notification, create_service
from tests.app.conftest import (
sample_job as create_sample_job,
sample_notification_history as create_notification_history,
create_custom_template
)
create_custom_template,
sample_notification)
from tests.conftest import set_config_values
from unittest.mock import call, patch, PropertyMock
@@ -409,3 +409,22 @@ def test_switch_providers_on_slow_delivery_does_not_switch_based_on_older_notifi
switch_current_sms_provider_on_slow_delivery()
current_provider = get_current_provider('sms')
assert starting_provider.identifier == current_provider.identifier
@freeze_time("2017-05-01 14:00:00")
def test_should_send_all_scheduled_notifications_to_deliver_queue(notify_db,
notify_db_session,
sample_template, mocker):
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms')
message_to_deliver = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
template=sample_template, scheduled_for="2017-05-01 13:50:00")
sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
template=sample_template, scheduled_for="2017-05-01 10:50:00", status='delivered')
sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
template=sample_template)
sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
template=sample_template, scheduled_for="2017-05-01 14:30:00")
send_scheduled_notifications()
mocked.apply_async.assert_called_once_with([str(message_to_deliver.id)], queue='send-sms')