mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Method to return scheduled notifications that are ready to send
This commit is contained in:
@@ -27,7 +27,7 @@ from app.models import (
|
|||||||
NOTIFICATION_PERMANENT_FAILURE,
|
NOTIFICATION_PERMANENT_FAILURE,
|
||||||
KEY_TYPE_NORMAL, KEY_TYPE_TEST,
|
KEY_TYPE_NORMAL, KEY_TYPE_TEST,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
NOTIFICATION_SENT)
|
NOTIFICATION_SENT, ScheduledNotification)
|
||||||
|
|
||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional
|
||||||
from app.statsd_decorators import statsd
|
from app.statsd_decorators import statsd
|
||||||
@@ -469,3 +469,9 @@ def dao_get_notifications_by_to_field(service_id, search_term):
|
|||||||
def dao_created_scheduled_notification(scheduled_notification):
|
def dao_created_scheduled_notification(scheduled_notification):
|
||||||
db.session.add(scheduled_notification)
|
db.session.add(scheduled_notification)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@statsd(namespace="dao")
|
||||||
|
def dao_get_scheduled_notifications():
|
||||||
|
scheduled_notifications = ScheduledNotification.query.filter(ScheduledNotification.scheduled_for < datetime.utcnow()).all()
|
||||||
|
return scheduled_notifications
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ from app.dao.notifications_dao import (
|
|||||||
is_delivery_slow_for_provider,
|
is_delivery_slow_for_provider,
|
||||||
dao_update_notifications_sent_to_dvla,
|
dao_update_notifications_sent_to_dvla,
|
||||||
dao_get_notifications_by_to_field,
|
dao_get_notifications_by_to_field,
|
||||||
dao_created_scheduled_notification)
|
dao_created_scheduled_notification, dao_get_scheduled_notifications)
|
||||||
|
|
||||||
from app.dao.services_dao import dao_update_service
|
from app.dao.services_dao import dao_update_service
|
||||||
from tests.app.db import create_notification
|
from tests.app.db import create_notification
|
||||||
@@ -1704,3 +1704,13 @@ def test_dao_created_scheduled_notification(sample_notification):
|
|||||||
assert len(saved_notification) == 1
|
assert len(saved_notification) == 1
|
||||||
assert saved_notification[0].notification_id == sample_notification.id
|
assert saved_notification[0].notification_id == sample_notification.id
|
||||||
assert saved_notification[0].scheduled_for == datetime(2017, 1, 5, 14)
|
assert saved_notification[0].scheduled_for == datetime(2017, 1, 5, 14)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dao_get_scheduled_notifications(notify_db, notify_db_session, sample_template):
|
||||||
|
notification_1 = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
|
||||||
|
template=sample_template, scheduled_for='2017-05-05 14:00:00')
|
||||||
|
sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
|
||||||
|
template=sample_template)
|
||||||
|
scheduled_notifications = dao_get_scheduled_notifications()
|
||||||
|
assert len(scheduled_notifications) == 1
|
||||||
|
assert scheduled_notifications[0].notification_id == notification_1.id
|
||||||
|
|||||||
Reference in New Issue
Block a user