Cleaning up tests.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-01-16 14:46:17 -05:00
parent 9523cc1d97
commit 8c6046b03b
33 changed files with 268 additions and 315 deletions

View File

@@ -13,14 +13,11 @@ from app.celery.reporting_tasks import (
)
from app.config import QueueNames
from app.dao.fact_billing_dao import get_rate
from app.enums import NotificationType, KeyType
from app.models import (
KEY_TYPE_NORMAL,
KEY_TYPE_TEAM,
KEY_TYPE_TEST,
FactBilling,
FactNotificationStatus,
Notification,
NotificationType,
)
from tests.app.db import (
create_notification,
@@ -431,12 +428,12 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
# team API key notifications are included
create_notification(
template=second_template, status="sending", key_type=KEY_TYPE_TEAM
template=second_template, status="sending", key_type=KeyType.TEAM
)
# test notifications are ignored
create_notification(
template=second_template, status="sending", key_type=KEY_TYPE_TEST
template=second_template, status="sending", key_type=KeyType.TEST
)
# historical notifications are included
@@ -471,7 +468,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
assert email_delivered_row.notification_type == "email"
assert email_delivered_row.notification_status == "delivered"
assert email_delivered_row.notification_count == 1
assert email_delivered_row.key_type == KEY_TYPE_NORMAL
assert email_delivered_row.key_type == KeyType.NORMAL
email_sending_row = new_fact_data[1]
assert email_sending_row.template_id == second_template.id
@@ -479,7 +476,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
assert email_sending_row.notification_type == "email"
assert email_sending_row.notification_status == "failed"
assert email_sending_row.notification_count == 1
assert email_sending_row.key_type == KEY_TYPE_NORMAL
assert email_sending_row.key_type == KeyType.NORMAL
email_failure_row = new_fact_data[2]
assert email_failure_row.local_date == process_day
@@ -489,7 +486,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
assert email_failure_row.notification_type == "email"
assert email_failure_row.notification_status == "sending"
assert email_failure_row.notification_count == 1
assert email_failure_row.key_type == KEY_TYPE_TEAM
assert email_failure_row.key_type == KeyType.TEAM
sms_delivered_row = new_fact_data[3]
assert sms_delivered_row.template_id == first_template.id
@@ -497,7 +494,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
assert sms_delivered_row.notification_type == "sms"
assert sms_delivered_row.notification_status == "delivered"
assert sms_delivered_row.notification_count == 1
assert sms_delivered_row.key_type == KEY_TYPE_NORMAL
assert sms_delivered_row.key_type == KeyType.NORMAL
def test_create_nightly_notification_status_for_service_and_day_overwrites_old_data(

View File

@@ -19,12 +19,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.models import (
JOB_STATUS_ERROR,
JOB_STATUS_FINISHED,
JOB_STATUS_IN_PROGRESS,
JOB_STATUS_PENDING,
)
from app.enums import JobStatus
from tests.app import load_example_csv
from tests.app.db import create_job, create_notification, create_template
@@ -156,7 +151,7 @@ def test_check_job_status_task_calls_process_incomplete_jobs(mocker, sample_temp
notification_count=3,
created_at=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_IN_PROGRESS,
job_status=JobStatus.IN_PROGRESS,
)
create_notification(template=sample_template, job=job)
check_job_status()
@@ -174,7 +169,7 @@ def test_check_job_status_task_calls_process_incomplete_jobs_when_scheduled_job_
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_IN_PROGRESS,
job_status=JobStatus.IN_PROGRESS,
)
check_job_status()
@@ -190,7 +185,7 @@ def test_check_job_status_task_calls_process_incomplete_jobs_for_pending_schedul
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_PENDING,
job_status=JobStatus.PENDING,
)
check_job_status()
@@ -207,7 +202,7 @@ def test_check_job_status_task_does_not_call_process_incomplete_jobs_for_non_sch
template=sample_template,
notification_count=3,
created_at=datetime.utcnow() - timedelta(hours=2),
job_status=JOB_STATUS_PENDING,
job_status=JobStatus.PENDING,
)
check_job_status()
@@ -224,7 +219,7 @@ def test_check_job_status_task_calls_process_incomplete_jobs_for_multiple_jobs(
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_IN_PROGRESS,
job_status=JobStatus.IN_PROGRESS,
)
job_2 = create_job(
template=sample_template,
@@ -232,7 +227,7 @@ def test_check_job_status_task_calls_process_incomplete_jobs_for_multiple_jobs(
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_IN_PROGRESS,
job_status=JobStatus.IN_PROGRESS,
)
check_job_status()
@@ -249,21 +244,21 @@ def test_check_job_status_task_only_sends_old_tasks(mocker, sample_template):
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_IN_PROGRESS,
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),
job_status=JOB_STATUS_IN_PROGRESS,
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),
job_status=JOB_STATUS_PENDING,
job_status=JobStatus.PENDING,
)
check_job_status()
@@ -279,21 +274,21 @@ def test_check_job_status_task_sets_jobs_to_error(mocker, sample_template):
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_IN_PROGRESS,
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),
job_status=JOB_STATUS_IN_PROGRESS,
job_status=JobStatus.IN_PROGRESS,
)
check_job_status()
# job 2 not in celery task
mock_celery.assert_called_once_with([[str(job.id)]], queue=QueueNames.JOBS)
assert job.job_status == JOB_STATUS_ERROR
assert job_2.job_status == JOB_STATUS_IN_PROGRESS
assert job.job_status == JobStatus.ERROR
assert job_2.job_status == JobStatus.IN_PROGRESS
def test_replay_created_notifications(notify_db_session, sample_service, mocker):
@@ -352,14 +347,14 @@ def test_check_job_status_task_does_not_raise_error(sample_template):
created_at=datetime.utcnow() - timedelta(hours=2),
scheduled_for=datetime.utcnow() - timedelta(minutes=31),
processing_started=datetime.utcnow() - timedelta(minutes=31),
job_status=JOB_STATUS_FINISHED,
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),
job_status=JOB_STATUS_FINISHED,
job_status=JobStatus.FINISHED,
)
check_job_status()
@@ -389,7 +384,7 @@ def test_check_for_missing_rows_in_completed_jobs_ignores_old_and_new_jobs(
job = create_job(
template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - offset,
)
for i in range(0, 4):
@@ -411,7 +406,7 @@ def test_check_for_missing_rows_in_completed_jobs(mocker, sample_email_template)
job = create_job(
template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=20),
)
for i in range(0, 4):
@@ -438,7 +433,7 @@ def test_check_for_missing_rows_in_completed_jobs_calls_save_email(
job = create_job(
template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=20),
)
for i in range(0, 4):
@@ -468,7 +463,7 @@ def test_check_for_missing_rows_in_completed_jobs_uses_sender_id(
job = create_job(
template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
job_status=JobStatus.FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=20),
)
for i in range(0, 4):

View File

@@ -12,7 +12,8 @@ from app.celery.test_key_tasks import (
sns_callback,
)
from app.config import QueueNames
from app.models import NOTIFICATION_DELIVERED, NOTIFICATION_FAILED, Notification
from app.enums import NotificationStatus
from app.models import Notification
from tests.conftest import Matcher
dvla_response_file_matcher = Matcher(
@@ -28,7 +29,7 @@ def test_make_sns_callback(notify_api, rmock, mocker):
)
n = Notification()
n.id = 1234
n.status = NOTIFICATION_DELIVERED
n.status = NotificationStatus.DELIVERED
get_notification_by_id.return_value = n
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
send_sms_response("sns", "1234")
@@ -45,7 +46,7 @@ def test_callback_logs_on_api_call_failure(notify_api, rmock, mocker):
)
n = Notification()
n.id = 1234
n.status = NOTIFICATION_FAILED
n.status = NotificationStatus.FAILED
get_notification_by_id.return_value = n
rmock.request(
@@ -81,7 +82,7 @@ def test_delivered_sns_callback(mocker):
)
n = Notification()
n.id = 1234
n.status = NOTIFICATION_DELIVERED
n.status = NotificationStatus.DELIVERED
get_notification_by_id.return_value = n
data = json.loads(sns_callback("1234"))