diff --git a/app/dao/fact_notification_status_dao.py b/app/dao/fact_notification_status_dao.py index 0cd744acd..60b4bb92c 100644 --- a/app/dao/fact_notification_status_dao.py +++ b/app/dao/fact_notification_status_dao.py @@ -174,7 +174,7 @@ def fetch_notification_status_totals_for_all_services(start_date, end_date): FactNotificationStatus.key_type, ) today = get_london_midnight_in_utc(datetime.utcnow()) - if start_date <= today.date() <= end_date: + if start_date <= datetime.utcnow().date() <= end_date: stats_for_today = db.session.query( Notification.notification_type.cast(db.Text).label('notification_type'), Notification.status, diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index fecf8d696..14c8a0b8f 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -18,6 +18,7 @@ from app.dao.fact_notification_status_dao import ( from app.models import FactNotificationStatus, KEY_TYPE_TEST, KEY_TYPE_TEAM, EMAIL_TYPE, SMS_TYPE, LETTER_TYPE from freezegun import freeze_time +from app.utils import get_london_midnight_in_utc from tests.app.db import create_notification, create_service, create_template, create_ft_notification_status, create_job @@ -319,6 +320,42 @@ def test_fetch_notification_status_totals_for_all_services( assert results[3].count == expected_sms +@freeze_time('2018-04-21 14:00') +def test_fetch_notification_status_totals_for_all_services_works_in_bst( + notify_db_session +): + service_1 = create_service(service_name='service_1') + sms_template = create_template(service=service_1, template_type=SMS_TYPE) + email_template = create_template(service=service_1, template_type=EMAIL_TYPE) + + create_notification(sms_template, created_at=datetime(2018, 4, 20, 12, 0, 0), status='delivered') + create_notification(sms_template, created_at=datetime(2018, 4, 21, 11, 0, 0), status='created') + create_notification(sms_template, created_at=datetime(2018, 4, 21, 12, 0, 0), status='delivered') + create_notification(email_template, created_at=datetime(2018, 4, 21, 13, 0, 0), status='delivered') + create_notification(email_template, created_at=datetime(2018, 4, 21, 14, 0, 0), status='delivered') + + results = sorted( + fetch_notification_status_totals_for_all_services( + start_date=date(2018, 4, 21), end_date=date(2018, 4, 21)), + key=lambda x: (x.notification_type, x.status) + ) + + assert len(results) == 3 + print(results) + + assert results[0].notification_type == 'email' + assert results[0].status == 'delivered' + assert results[0].count == 2 + + assert results[1].notification_type == 'sms' + assert results[1].status == 'created' + assert results[1].count == 1 + + assert results[2].notification_type == 'sms' + assert results[2].status == 'delivered' + assert results[2].count == 1 + + def set_up_data(): service_2 = create_service(service_name='service_2') create_template(service=service_2, template_type=LETTER_TYPE)