From 80c6c677db95c7f775407253616d42d152ab1f12 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 31 May 2023 10:07:27 -0700 Subject: [PATCH] clean up remaining todays() --- app/dao/services_dao.py | 4 ++-- tests/app/celery/test_reporting_tasks.py | 4 ++-- tests/app/complaint/test_complaint_rest.py | 4 ++-- tests/app/dao/test_fact_billing_dao.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 793211d80..2c1d9a381 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -1,5 +1,5 @@ import uuid -from datetime import date, datetime, timedelta +from datetime import datetime, timedelta from flask import current_app from sqlalchemy import Float, cast @@ -387,7 +387,7 @@ def delete_service_and_all_associated_db_objects(service): def dao_fetch_todays_stats_for_service(service_id): - today = date.today() + today = datetime.utcnow().date() start_date = get_midnight_in_utc(today) return db.session.query( Notification.notification_type, diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index cbbbdefbf..f2dc6b549 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -426,7 +426,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio second_service = create_service(service_name='second Service') second_template = create_template(service=second_service, template_type='email') - process_day = date.today() - timedelta(days=5) + process_day = datetime.utcnow().date() - timedelta(days=5) with freeze_time(datetime.combine(process_day, time.max)): create_notification(template=first_template, status='delivered') create_notification(template=second_template, status='temporary-failure') @@ -441,7 +441,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio create_notification_history(template=second_template, status='delivered') # these created notifications from a different day get ignored - with freeze_time(datetime.combine(date.today() - timedelta(days=4), time.max)): + with freeze_time(datetime.combine(datetime.utcnow().date() - timedelta(days=4), time.max)): create_notification(template=first_template) create_notification_history(template=second_template) diff --git a/tests/app/complaint/test_complaint_rest.py b/tests/app/complaint/test_complaint_rest.py index 5f72e4ee2..9dd5aca06 100644 --- a/tests/app/complaint/test_complaint_rest.py +++ b/tests/app/complaint/test_complaint_rest.py @@ -1,5 +1,5 @@ import json -from datetime import date +from datetime import date, datetime from flask import url_for from freezegun import freeze_time @@ -74,7 +74,7 @@ def test_get_complaint_sets_start_and_end_date_to_today_if_not_specified(mocker, dao_mock = mocker.patch('app.complaint.complaint_rest.fetch_count_of_complaints', return_value=5) response = client.get(url_for('complaint.get_complaint_count'), headers=[create_admin_authorization_header()]) - dao_mock.assert_called_once_with(start_date=date.today(), end_date=date.today()) + dao_mock.assert_called_once_with(start_date=datetime.utcnow().date(), end_date=datetime.utcnow().date()) assert response.status_code == 200 assert json.loads(response.get_data(as_text=True)) == 5 diff --git a/tests/app/dao/test_fact_billing_dao.py b/tests/app/dao/test_fact_billing_dao.py index e900c0cbe..4edd7a533 100644 --- a/tests/app/dao/test_fact_billing_dao.py +++ b/tests/app/dao/test_fact_billing_dao.py @@ -714,7 +714,7 @@ def test_fetch_usage_year_for_organisation_only_queries_present_year(notify_db_s last_year = current_year - 1 date_two_years_ago = date(2021, 3, 31) date_in_last_financial_year = date(2022, 3, 31) - date_in_this_year = date.today() + date_in_this_year = datetime.utcnow().date() org = create_organisation(name='Organisation 1')