From db0d82923890dd4f96f5146cac5456ee69a07cf5 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 31 May 2023 17:52:16 -0700 Subject: [PATCH] notify-281 fix time-sensitive tests --- app/dao/services_dao.py | 3 ++- app/service/rest.py | 1 - tests/app/celery/test_reporting_tasks.py | 2 +- tests/app/db.py | 1 - tests/app/template/test_rest_history.py | 5 +++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 4456d32b2..ea5035a8a 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -404,10 +404,11 @@ def dao_fetch_todays_stats_for_service(service_id): def dao_fetch_todays_stats_for_all_services(include_from_test_key=True, only_active=True): - today = date.today() + today = datetime.utcnow().date() start_date = get_midnight_in_utc(today) end_date = get_midnight_in_utc(today + timedelta(days=1)) + subquery = db.session.query( Notification.notification_type, Notification.status, diff --git a/app/service/rest.py b/app/service/rest.py index abeb41e48..43d3ec63a 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -527,7 +527,6 @@ def get_detailed_services(start_date, end_date, only_active=False, include_from_ stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=include_from_test_key, only_active=only_active) else: - stats = fetch_stats_for_all_services_by_date_range(start_date=start_date, end_date=end_date, include_from_test_key=include_from_test_key, diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index d0d6c4e3e..cbbbdefbf 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -495,7 +495,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio def test_create_nightly_notification_status_for_service_and_day_overwrites_old_data(notify_db_session): first_service = create_service(service_name='First Service') first_template = create_template(service=first_service) - process_day = date.today() + process_day = datetime.utcnow().date() # first run: one notification, expect one row (just one status) notification = create_notification(template=first_template, status='sending') diff --git a/tests/app/db.py b/tests/app/db.py index 92320a862..30023f437 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -297,7 +297,6 @@ def create_notification( } notification = Notification(**data) dao_create_notification(notification) - return notification diff --git a/tests/app/template/test_rest_history.py b/tests/app/template/test_rest_history.py index 3e6f400d2..8f8b82ef2 100644 --- a/tests/app/template/test_rest_history.py +++ b/tests/app/template/test_rest_history.py @@ -1,5 +1,5 @@ import json -from datetime import date, datetime +from datetime import datetime from flask import url_for @@ -27,7 +27,8 @@ def test_template_history_version(notify_api, sample_user, sample_template): assert json_resp['data']['version'] == 1 assert json_resp['data']['process_type'] == 'normal' assert json_resp['data']['created_by']['name'] == sample_user.name - assert datetime.strptime(json_resp['data']['created_at'], '%Y-%m-%d %H:%M:%S.%f').date() == date.today() + assert datetime.strptime(json_resp['data']['created_at'], '%Y-%m-%d %H:%M:%S.%f').date() == \ + datetime.utcnow().date() def test_previous_template_history_version(notify_api, sample_template):