remove datetime.utcnow()

This commit is contained in:
Kenneth Kehl
2024-05-23 13:59:51 -07:00
parent 752a13fbd2
commit 905df17f65
83 changed files with 591 additions and 570 deletions

View File

@@ -1,5 +1,5 @@
from collections import namedtuple
from datetime import datetime, timedelta
from datetime import timedelta
from unittest import mock
from unittest.mock import ANY, call
@@ -18,6 +18,7 @@ from app.celery.scheduled_tasks import (
from app.config import QueueNames, Test
from app.dao.jobs_dao import dao_get_job_by_id
from app.enums import JobStatus, NotificationStatus, TemplateType
from app.utils import utc_now
from notifications_utils.clients.zendesk.zendesk_client import NotifySupportTicket
from tests.app import load_example_csv
from tests.app.db import create_job, create_notification, create_template
@@ -51,7 +52,7 @@ def test_should_call_expire_or_delete_invotations_on_expire_or_delete_invitation
def test_should_update_scheduled_jobs_and_put_on_queue(mocker, sample_template):
mocked = mocker.patch("app.celery.tasks.process_job.apply_async")
one_minute_in_the_past = datetime.utcnow() - timedelta(minutes=1)
one_minute_in_the_past = utc_now() - timedelta(minutes=1)
job = create_job(
sample_template,
job_status=JobStatus.SCHEDULED,
@@ -68,9 +69,9 @@ def test_should_update_scheduled_jobs_and_put_on_queue(mocker, sample_template):
def test_should_update_all_scheduled_jobs_and_put_on_queue(sample_template, mocker):
mocked = mocker.patch("app.celery.tasks.process_job.apply_async")
one_minute_in_the_past = datetime.utcnow() - timedelta(minutes=1)
ten_minutes_in_the_past = datetime.utcnow() - timedelta(minutes=10)
twenty_minutes_in_the_past = datetime.utcnow() - timedelta(minutes=20)
one_minute_in_the_past = utc_now() - timedelta(minutes=1)
ten_minutes_in_the_past = utc_now() - timedelta(minutes=10)
twenty_minutes_in_the_past = utc_now() - timedelta(minutes=20)
job_1 = create_job(
sample_template,
job_status=JobStatus.SCHEDULED,
@@ -107,8 +108,8 @@ def test_check_job_status_task_calls_process_incomplete_jobs(mocker, sample_temp
job = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.IN_PROGRESS,
)
create_notification(template=sample_template, job=job)
@@ -124,9 +125,9 @@ def test_check_job_status_task_calls_process_incomplete_jobs_when_scheduled_job_
job = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.IN_PROGRESS,
)
check_job_status()
@@ -141,8 +142,8 @@ def test_check_job_status_task_calls_process_incomplete_jobs_for_pending_schedul
job = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
job_status=JobStatus.PENDING,
)
@@ -159,7 +160,7 @@ def test_check_job_status_task_does_not_call_process_incomplete_jobs_for_non_sch
create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
created_at=utc_now() - timedelta(hours=2),
job_status=JobStatus.PENDING,
)
check_job_status()
@@ -174,17 +175,17 @@ def test_check_job_status_task_calls_process_incomplete_jobs_for_multiple_jobs(
job = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.IN_PROGRESS,
)
job_2 = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.IN_PROGRESS,
)
check_job_status()
@@ -199,23 +200,23 @@ def test_check_job_status_task_only_sends_old_tasks(mocker, sample_template):
job = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.IN_PROGRESS,
)
create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=29),
created_at=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=29),
job_status=JobStatus.IN_PROGRESS,
)
create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(minutes=50),
scheduled_for=datetime.utcnow() - timedelta(minutes=29),
created_at=utc_now() - timedelta(minutes=50),
scheduled_for=utc_now() - timedelta(minutes=29),
job_status=JobStatus.PENDING,
)
check_job_status()
@@ -229,16 +230,16 @@ def test_check_job_status_task_sets_jobs_to_error(mocker, sample_template):
job = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.IN_PROGRESS,
)
job_2 = create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=29),
created_at=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=29),
job_status=JobStatus.IN_PROGRESS,
)
check_job_status()
@@ -267,33 +268,33 @@ def test_replay_created_notifications(notify_db_session, sample_service, mocker)
# notifications expected to be resent
old_sms = create_notification(
template=sms_template,
created_at=datetime.utcnow() - timedelta(seconds=older_than),
created_at=utc_now() - timedelta(seconds=older_than),
status=NotificationStatus.CREATED,
)
old_email = create_notification(
template=email_template,
created_at=datetime.utcnow() - timedelta(seconds=older_than),
created_at=utc_now() - timedelta(seconds=older_than),
status=NotificationStatus.CREATED,
)
# notifications that are not to be resent
create_notification(
template=sms_template,
created_at=datetime.utcnow() - timedelta(seconds=older_than),
created_at=utc_now() - timedelta(seconds=older_than),
status=NotificationStatus.SENDING,
)
create_notification(
template=email_template,
created_at=datetime.utcnow() - timedelta(seconds=older_than),
created_at=utc_now() - timedelta(seconds=older_than),
status=NotificationStatus.DELIVERED,
)
create_notification(
template=sms_template,
created_at=datetime.utcnow(),
created_at=utc_now(),
status=NotificationStatus.CREATED,
)
create_notification(
template=email_template,
created_at=datetime.utcnow(),
created_at=utc_now(),
status=NotificationStatus.CREATED,
)
@@ -310,16 +311,16 @@ def test_check_job_status_task_does_not_raise_error(sample_template):
create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(hours=2),
scheduled_for=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.FINISHED,
)
create_job(
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
created_at=utc_now() - timedelta(minutes=31),
processing_started=utc_now() - timedelta(minutes=31),
job_status=JobStatus.FINISHED,
)
@@ -351,7 +352,7 @@ def test_check_for_missing_rows_in_completed_jobs_ignores_old_and_new_jobs(
template=sample_email_template,
notification_count=5,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - offset,
processing_finished=utc_now() - offset,
)
for i in range(0, 4):
create_notification(job=job, job_row_number=i)
@@ -373,7 +374,7 @@ def test_check_for_missing_rows_in_completed_jobs(mocker, sample_email_template)
template=sample_email_template,
notification_count=5,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=20),
processing_finished=utc_now() - timedelta(minutes=20),
)
for i in range(0, 4):
create_notification(job=job, job_row_number=i)
@@ -400,7 +401,7 @@ def test_check_for_missing_rows_in_completed_jobs_calls_save_email(
template=sample_email_template,
notification_count=5,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=20),
processing_finished=utc_now() - timedelta(minutes=20),
)
for i in range(0, 4):
create_notification(job=job, job_row_number=i)
@@ -430,7 +431,7 @@ def test_check_for_missing_rows_in_completed_jobs_uses_sender_id(
template=sample_email_template,
notification_count=5,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=20),
processing_finished=utc_now() - timedelta(minutes=20),
)
for i in range(0, 4):
create_notification(job=job, job_row_number=i)