mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Add dao method to get count of slow delivery notifications by provider
This commit is contained in:
@@ -40,7 +40,9 @@ from app.dao.notifications_dao import (
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
dao_timeout_notifications,
|
||||
get_financial_year,
|
||||
get_april_fools)
|
||||
get_april_fools,
|
||||
get_count_of_slow_delivery_sms_notifications_for_provider
|
||||
)
|
||||
|
||||
from app.dao.services_dao import dao_update_service
|
||||
from tests.app.conftest import (
|
||||
@@ -1422,3 +1424,229 @@ def test_get_total_sent_notifications_for_email_excludes_sms_counts(
|
||||
|
||||
total_count = get_total_sent_notifications_in_date_range(start_date, end_date, 'email')
|
||||
assert total_count == 2
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_get_count_of_slow_delivery_sms_notifications_returns_after_created_time(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
now = datetime.utcnow()
|
||||
a_second_ago = now - timedelta(seconds=1)
|
||||
five_minutes_from_now = now + timedelta(minutes=5)
|
||||
|
||||
notification_five_minutes_to_deliver = partial(
|
||||
sample_notification,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_at=now,
|
||||
sent_by='mmg',
|
||||
updated_at=five_minutes_from_now
|
||||
)
|
||||
|
||||
noti1 = notification_five_minutes_to_deliver(created_at=a_second_ago)
|
||||
notification_five_minutes_to_deliver(created_at=a_second_ago)
|
||||
notification_five_minutes_to_deliver(created_at=now)
|
||||
|
||||
count = get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
provider='mmg',
|
||||
threshold=1,
|
||||
delivery_time=timedelta(minutes=5),
|
||||
service_id=noti1.service_id,
|
||||
template_id=noti1.template_id
|
||||
)
|
||||
|
||||
assert count.total == 1
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_get_count_of_slow_delivery_sms_notifications_returns_after_sent_time(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
now = datetime.utcnow()
|
||||
one_minute_from_now = now + timedelta(minutes=1)
|
||||
five_minutes_from_now = now + timedelta(minutes=5)
|
||||
|
||||
notification_five_minutes_to_deliver = partial(
|
||||
sample_notification,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_by='mmg',
|
||||
updated_at=five_minutes_from_now
|
||||
)
|
||||
|
||||
noti1 = notification_five_minutes_to_deliver(created_at=now, sent_at=now)
|
||||
notification_five_minutes_to_deliver(created_at=now, sent_at=one_minute_from_now)
|
||||
notification_five_minutes_to_deliver(created_at=now, sent_at=one_minute_from_now)
|
||||
|
||||
count = get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at=now,
|
||||
sent_at=one_minute_from_now,
|
||||
provider='mmg',
|
||||
threshold=2,
|
||||
delivery_time=timedelta(minutes=3),
|
||||
service_id=noti1.service_id,
|
||||
template_id=noti1.template_id
|
||||
)
|
||||
|
||||
assert count.total == 2
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_get_count_of_slow_delivery_sms_notifications_observes_threshold(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
now = datetime.utcnow()
|
||||
five_minutes_from_now = now + timedelta(minutes=5)
|
||||
|
||||
notification_five_minutes_to_deliver = partial(
|
||||
sample_notification,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_at=now,
|
||||
sent_by='mmg',
|
||||
updated_at=five_minutes_from_now
|
||||
)
|
||||
|
||||
noti1 = notification_five_minutes_to_deliver(created_at=now)
|
||||
notification_five_minutes_to_deliver(created_at=now)
|
||||
|
||||
count = get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
provider='mmg',
|
||||
threshold=3,
|
||||
delivery_time=timedelta(minutes=5),
|
||||
service_id=noti1.service_id,
|
||||
template_id=noti1.template_id
|
||||
)
|
||||
|
||||
assert not count
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_get_count_of_slow_delivery_sms_notifications_returns_status_delivered_only(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
now = datetime.utcnow()
|
||||
five_minutes_from_now = now + timedelta(minutes=5)
|
||||
|
||||
notification_five_minutes_to_deliver = partial(
|
||||
sample_notification,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_template,
|
||||
sent_at=now,
|
||||
sent_by='firetext',
|
||||
created_at=now,
|
||||
updated_at=five_minutes_from_now
|
||||
)
|
||||
|
||||
noti1 = notification_five_minutes_to_deliver(status='created')
|
||||
notification_five_minutes_to_deliver(status='sending')
|
||||
notification_five_minutes_to_deliver(status='delivered')
|
||||
notification_five_minutes_to_deliver(status='delivered')
|
||||
|
||||
count = get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
provider='firetext',
|
||||
threshold=1,
|
||||
delivery_time=timedelta(minutes=5),
|
||||
service_id=noti1.service_id,
|
||||
template_id=noti1.template_id
|
||||
)
|
||||
|
||||
assert count.total == 2
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_get_count_of_slow_delivery_sms_notifications_returns_slow_delivery_time_only(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
now = datetime.utcnow()
|
||||
five_minutes_from_now = now + timedelta(minutes=5)
|
||||
|
||||
notification = partial(
|
||||
sample_notification,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_template,
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
sent_by='mmg',
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
noti1 = notification(updated_at=five_minutes_from_now - timedelta(seconds=1))
|
||||
noti1 = notification(updated_at=five_minutes_from_now - timedelta(seconds=1))
|
||||
notification(updated_at=five_minutes_from_now)
|
||||
notification(updated_at=five_minutes_from_now)
|
||||
notification(updated_at=five_minutes_from_now)
|
||||
|
||||
count = get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
provider='mmg',
|
||||
threshold=1,
|
||||
delivery_time=timedelta(minutes=5),
|
||||
service_id=noti1.service_id,
|
||||
template_id=noti1.template_id
|
||||
)
|
||||
|
||||
assert count.total == 3
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_get_count_of_slow_delivery_sms_notifications_returns_provider_only(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
now = datetime.utcnow()
|
||||
five_minutes_from_now = now + timedelta(minutes=5)
|
||||
|
||||
notification = partial(
|
||||
sample_notification,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template=sample_template,
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
updated_at=five_minutes_from_now,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
noti1 = notification(sent_by='mmg')
|
||||
notification(sent_by='firetext')
|
||||
notification(sent_by='loadtesting')
|
||||
notification(sent_by='loadtesting')
|
||||
|
||||
count = get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at=now,
|
||||
sent_at=now,
|
||||
provider='mmg',
|
||||
threshold=1,
|
||||
delivery_time=timedelta(minutes=5),
|
||||
service_id=noti1.service_id,
|
||||
template_id=noti1.template_id
|
||||
)
|
||||
|
||||
assert count.sent_by == 'mmg'
|
||||
|
||||
Reference in New Issue
Block a user