mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-15 07:18:09 -04:00
remove datetime.utcnow()
This commit is contained in:
@@ -19,6 +19,7 @@ from app.celery.nightly_tasks import (
|
||||
)
|
||||
from app.enums import NotificationType, TemplateType
|
||||
from app.models import FactProcessingTime, Job
|
||||
from app.utils import utc_now
|
||||
from tests.app.db import (
|
||||
create_job,
|
||||
create_notification,
|
||||
@@ -62,7 +63,7 @@ def test_will_remove_csv_files_for_jobs_older_than_seven_days(
|
||||
"""
|
||||
mocker.patch("app.celery.nightly_tasks.s3.remove_job_from_s3")
|
||||
|
||||
seven_days_ago = datetime.utcnow() - timedelta(days=7)
|
||||
seven_days_ago = utc_now() - timedelta(days=7)
|
||||
just_under_seven_days = seven_days_ago + timedelta(seconds=1)
|
||||
eight_days_ago = seven_days_ago - timedelta(days=1)
|
||||
nine_days_ago = eight_days_ago - timedelta(days=1)
|
||||
@@ -115,9 +116,9 @@ def test_will_remove_csv_files_for_jobs_older_than_retention_period(
|
||||
template_type=TemplateType.EMAIL,
|
||||
)
|
||||
|
||||
four_days_ago = datetime.utcnow() - timedelta(days=4)
|
||||
eight_days_ago = datetime.utcnow() - timedelta(days=8)
|
||||
thirty_one_days_ago = datetime.utcnow() - timedelta(days=31)
|
||||
four_days_ago = utc_now() - timedelta(days=4)
|
||||
eight_days_ago = utc_now() - timedelta(days=8)
|
||||
thirty_one_days_ago = utc_now() - timedelta(days=31)
|
||||
|
||||
job1_to_delete = create_job(sms_template_service_1, created_at=four_days_ago)
|
||||
job2_to_delete = create_job(email_template_service_1, created_at=eight_days_ago)
|
||||
@@ -369,21 +370,21 @@ def test_delete_notifications_task_calls_task_for_services_that_have_sent_notifi
|
||||
# will be deleted as service has no custom retention, but past our default 7 days
|
||||
create_notification(
|
||||
service_will_delete_1.templates[0],
|
||||
created_at=datetime.utcnow() - timedelta(days=8),
|
||||
created_at=utc_now() - timedelta(days=8),
|
||||
)
|
||||
create_notification(
|
||||
service_will_delete_2.templates[0],
|
||||
created_at=datetime.utcnow() - timedelta(days=8),
|
||||
created_at=utc_now() - timedelta(days=8),
|
||||
)
|
||||
|
||||
# will be kept as it's recent, and we won't run delete_notifications_for_service_and_type
|
||||
create_notification(
|
||||
nothing_to_delete_sms_template, created_at=datetime.utcnow() - timedelta(days=2)
|
||||
nothing_to_delete_sms_template, created_at=utc_now() - timedelta(days=2)
|
||||
)
|
||||
# this is an old notification, but for email not sms, so we won't run delete_notifications_for_service_and_type
|
||||
create_notification(
|
||||
nothing_to_delete_email_template,
|
||||
created_at=datetime.utcnow() - timedelta(days=8),
|
||||
created_at=utc_now() - timedelta(days=8),
|
||||
)
|
||||
|
||||
mock_subtask = mocker.patch(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from unittest.mock import ANY
|
||||
|
||||
from freezegun import freeze_time
|
||||
@@ -18,6 +17,7 @@ from app.celery.test_key_tasks import (
|
||||
from app.dao.notifications_dao import get_notification_by_id
|
||||
from app.enums import CallbackType, NotificationStatus
|
||||
from app.models import Complaint
|
||||
from app.utils import utc_now
|
||||
from tests.app.conftest import create_sample_notification
|
||||
from tests.app.db import (
|
||||
create_notification,
|
||||
@@ -136,7 +136,7 @@ def test_process_ses_results(sample_email_template):
|
||||
create_notification(
|
||||
sample_email_template,
|
||||
reference="ref1",
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
status=NotificationStatus.SENDING,
|
||||
)
|
||||
|
||||
@@ -147,7 +147,7 @@ def test_process_ses_results_retry_called(sample_email_template, mocker):
|
||||
create_notification(
|
||||
sample_email_template,
|
||||
reference="ref1",
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
status=NotificationStatus.SENDING,
|
||||
)
|
||||
mocker.patch(
|
||||
@@ -198,7 +198,7 @@ def test_ses_callback_should_update_notification_status(
|
||||
template=sample_email_template,
|
||||
reference="ref",
|
||||
status=NotificationStatus.SENDING,
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
)
|
||||
create_service_callback_api(
|
||||
service=sample_email_template.service, url="https://original_url.com"
|
||||
@@ -294,7 +294,7 @@ def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry(
|
||||
template=sample_email_template,
|
||||
reference="ref",
|
||||
status=NotificationStatus.SENDING,
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
)
|
||||
assert (
|
||||
get_notification_by_id(notification.id).status == NotificationStatus.SENDING
|
||||
@@ -318,7 +318,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
notify_db_session,
|
||||
template=sample_email_template,
|
||||
reference="ref1",
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
status=NotificationStatus.SENDING,
|
||||
)
|
||||
create_sample_notification(
|
||||
@@ -326,7 +326,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
notify_db_session,
|
||||
template=sample_email_template,
|
||||
reference="ref2",
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
status=NotificationStatus.SENDING,
|
||||
)
|
||||
create_sample_notification(
|
||||
@@ -334,7 +334,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
notify_db_session,
|
||||
template=sample_email_template,
|
||||
reference="ref3",
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
status=NotificationStatus.SENDING,
|
||||
)
|
||||
create_service_callback_api(
|
||||
@@ -358,7 +358,7 @@ def test_ses_callback_should_set_status_to_temporary_failure(
|
||||
template=sample_email_template,
|
||||
reference="ref",
|
||||
status=NotificationStatus.SENDING,
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
)
|
||||
create_service_callback_api(
|
||||
service=notification.service, url="https://original_url.com"
|
||||
@@ -384,7 +384,7 @@ def test_ses_callback_should_set_status_to_permanent_failure(
|
||||
template=sample_email_template,
|
||||
reference="ref",
|
||||
status=NotificationStatus.SENDING,
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
)
|
||||
create_service_callback_api(
|
||||
service=sample_email_template.service, url="https://original_url.com"
|
||||
@@ -412,7 +412,7 @@ def test_ses_callback_should_send_on_complaint_to_user_callback_api(
|
||||
notification = create_notification(
|
||||
template=sample_email_template,
|
||||
reference="ref1",
|
||||
sent_at=datetime.utcnow(),
|
||||
sent_at=utc_now(),
|
||||
status=NotificationStatus.SENDING,
|
||||
)
|
||||
response = ses_complaint_callback()
|
||||
|
||||
@@ -15,6 +15,7 @@ from app.config import QueueNames
|
||||
from app.dao.fact_billing_dao import get_rate
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType, TemplateType
|
||||
from app.models import FactBilling, FactNotificationStatus, Notification
|
||||
from app.utils import utc_now
|
||||
from tests.app.db import (
|
||||
create_notification,
|
||||
create_notification_history,
|
||||
@@ -420,7 +421,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
|
||||
template_type=TemplateType.EMAIL,
|
||||
)
|
||||
|
||||
process_day = datetime.utcnow().date() - timedelta(days=5)
|
||||
process_day = utc_now().date() - timedelta(days=5)
|
||||
with freeze_time(datetime.combine(process_day, time.max)):
|
||||
create_notification(
|
||||
template=first_template,
|
||||
@@ -449,9 +450,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
|
||||
)
|
||||
|
||||
# these created notifications from a different day get ignored
|
||||
with freeze_time(
|
||||
datetime.combine(datetime.utcnow().date() - timedelta(days=4), time.max)
|
||||
):
|
||||
with freeze_time(datetime.combine(utc_now().date() - timedelta(days=4), time.max)):
|
||||
create_notification(template=first_template)
|
||||
create_notification_history(template=second_template)
|
||||
|
||||
@@ -519,7 +518,7 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d
|
||||
):
|
||||
first_service = create_service(service_name="First Service")
|
||||
first_template = create_template(service=first_service)
|
||||
process_day = datetime.utcnow().date()
|
||||
process_day = utc_now().date()
|
||||
|
||||
# first run: one notification, expect one row (just one status)
|
||||
notification = create_notification(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.celery.service_callback_tasks import (
|
||||
send_delivery_status_to_service,
|
||||
)
|
||||
from app.enums import CallbackType, NotificationStatus, NotificationType
|
||||
from app.utils import DATETIME_FORMAT
|
||||
from app.utils import DATETIME_FORMAT, utc_now
|
||||
from tests.app.db import (
|
||||
create_complaint,
|
||||
create_notification,
|
||||
@@ -101,7 +101,7 @@ def test_send_complaint_to_service_posts_https_request_to_service_with_encrypted
|
||||
"complaint_id": str(complaint.id),
|
||||
"reference": notification.client_reference,
|
||||
"to": notification.to,
|
||||
"complaint_date": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
"complaint_date": utc_now().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
|
||||
assert request_mock.call_count == 1
|
||||
|
||||
@@ -36,7 +36,7 @@ from app.enums import (
|
||||
)
|
||||
from app.models import Job, Notification
|
||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
||||
from app.utils import DATETIME_FORMAT
|
||||
from app.utils import DATETIME_FORMAT, utc_now
|
||||
from notifications_utils.recipients import Row
|
||||
from notifications_utils.template import PlainTextEmailTemplate, SMSMessageTemplate
|
||||
from tests.app import load_example_csv
|
||||
@@ -419,7 +419,7 @@ def test_should_send_template_to_correct_sms_task_and_persist(
|
||||
== sample_template_with_placeholders.version
|
||||
)
|
||||
assert persisted_notification.status == NotificationStatus.CREATED
|
||||
assert persisted_notification.created_at <= datetime.utcnow()
|
||||
assert persisted_notification.created_at <= utc_now()
|
||||
assert not persisted_notification.sent_at
|
||||
assert not persisted_notification.sent_by
|
||||
assert not persisted_notification.job_id
|
||||
@@ -455,7 +455,7 @@ def test_should_save_sms_if_restricted_service_and_valid_number(
|
||||
assert persisted_notification.template_id == template.id
|
||||
assert persisted_notification.template_version == template.version
|
||||
assert persisted_notification.status == NotificationStatus.CREATED
|
||||
assert persisted_notification.created_at <= datetime.utcnow()
|
||||
assert persisted_notification.created_at <= utc_now()
|
||||
assert not persisted_notification.sent_at
|
||||
assert not persisted_notification.sent_by
|
||||
assert not persisted_notification.job_id
|
||||
@@ -565,7 +565,7 @@ def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, mocker)
|
||||
mocker.patch("app.celery.provider_tasks.deliver_sms.apply_async")
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
now = datetime.utcnow()
|
||||
now = utc_now()
|
||||
save_sms(
|
||||
sample_job.service.id,
|
||||
notification_id,
|
||||
@@ -676,7 +676,7 @@ def test_save_email_should_use_template_version_from_job_not_latest(
|
||||
dao_update_template(sample_email_template)
|
||||
t = dao_get_template_by_id(sample_email_template.id)
|
||||
assert t.version > version_on_notification
|
||||
now = datetime.utcnow()
|
||||
now = utc_now()
|
||||
save_email(
|
||||
sample_email_template.service_id,
|
||||
uuid.uuid4(),
|
||||
@@ -706,7 +706,7 @@ def test_should_use_email_template_subject_placeholders(
|
||||
mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
now = datetime.utcnow()
|
||||
now = utc_now()
|
||||
save_email(
|
||||
sample_email_template_with_placeholders.service_id,
|
||||
notification_id,
|
||||
@@ -791,7 +791,7 @@ def test_should_use_email_template_and_persist_without_personalisation(
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
|
||||
now = datetime.utcnow()
|
||||
now = utc_now()
|
||||
save_email(
|
||||
sample_email_template.service_id,
|
||||
notification_id,
|
||||
@@ -1157,9 +1157,9 @@ def test_process_incomplete_job_sms(mocker, sample_template):
|
||||
job = create_job(
|
||||
template=sample_template,
|
||||
notification_count=10,
|
||||
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.ERROR,
|
||||
)
|
||||
|
||||
@@ -1189,9 +1189,9 @@ def test_process_incomplete_job_with_notifications_all_sent(mocker, sample_templ
|
||||
job = create_job(
|
||||
template=sample_template,
|
||||
notification_count=10,
|
||||
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.ERROR,
|
||||
)
|
||||
|
||||
@@ -1229,9 +1229,9 @@ def test_process_incomplete_jobs_sms(mocker, sample_template):
|
||||
job = create_job(
|
||||
template=sample_template,
|
||||
notification_count=10,
|
||||
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.ERROR,
|
||||
)
|
||||
create_notification(sample_template, job, 0)
|
||||
@@ -1243,9 +1243,9 @@ def test_process_incomplete_jobs_sms(mocker, sample_template):
|
||||
job2 = create_job(
|
||||
template=sample_template,
|
||||
notification_count=10,
|
||||
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.ERROR,
|
||||
)
|
||||
|
||||
@@ -1282,9 +1282,9 @@ def test_process_incomplete_jobs_no_notifications_added(mocker, sample_template)
|
||||
job = create_job(
|
||||
template=sample_template,
|
||||
notification_count=10,
|
||||
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.ERROR,
|
||||
)
|
||||
|
||||
@@ -1339,9 +1339,9 @@ def test_process_incomplete_job_email(mocker, sample_email_template):
|
||||
job = create_job(
|
||||
template=sample_email_template,
|
||||
notification_count=10,
|
||||
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.ERROR,
|
||||
)
|
||||
|
||||
@@ -1371,22 +1371,22 @@ def test_process_incomplete_jobs_sets_status_to_in_progress_and_resets_processin
|
||||
|
||||
job1 = create_job(
|
||||
sample_template,
|
||||
processing_started=datetime.utcnow() - timedelta(minutes=30),
|
||||
processing_started=utc_now() - timedelta(minutes=30),
|
||||
job_status=JobStatus.ERROR,
|
||||
)
|
||||
job2 = create_job(
|
||||
sample_template,
|
||||
processing_started=datetime.utcnow() - timedelta(minutes=31),
|
||||
processing_started=utc_now() - timedelta(minutes=31),
|
||||
job_status=JobStatus.ERROR,
|
||||
)
|
||||
|
||||
process_incomplete_jobs([str(job1.id), str(job2.id)])
|
||||
|
||||
assert job1.job_status == JobStatus.IN_PROGRESS
|
||||
assert job1.processing_started == datetime.utcnow()
|
||||
assert job1.processing_started == utc_now()
|
||||
|
||||
assert job2.job_status == JobStatus.IN_PROGRESS
|
||||
assert job2.processing_started == datetime.utcnow()
|
||||
assert job2.processing_started == utc_now()
|
||||
|
||||
assert mock_process_incomplete_job.mock_calls == [
|
||||
call(str(job1.id)),
|
||||
@@ -1422,7 +1422,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
|
||||
"reply_to_text": None,
|
||||
"document_download_count": 0,
|
||||
"status": NotificationStatus.CREATED,
|
||||
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
"created_at": utc_now().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
@@ -1476,7 +1476,7 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
|
||||
"reply_to_text": "our.email@gov.uk",
|
||||
"document_download_count": 0,
|
||||
"status": NotificationStatus.CREATED,
|
||||
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
"created_at": utc_now().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
@@ -1621,7 +1621,7 @@ def test_save_api_tasks_use_cache(
|
||||
"reply_to_text": "our.email@gov.uk",
|
||||
"document_download_count": 0,
|
||||
"status": NotificationStatus.CREATED,
|
||||
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
"created_at": utc_now().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user