mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
More changes for enums.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -17,7 +17,7 @@ from app.celery.nightly_tasks import (
|
||||
save_daily_notification_processing_time,
|
||||
timeout_notifications,
|
||||
)
|
||||
from app.models import EMAIL_TYPE, SMS_TYPE, FactProcessingTime, Job
|
||||
from app.models import FactProcessingTime, Job, NotificationType
|
||||
from tests.app.db import (
|
||||
create_job,
|
||||
create_notification,
|
||||
@@ -95,10 +95,10 @@ def test_will_remove_csv_files_for_jobs_older_than_retention_period(
|
||||
service_1 = create_service(service_name="service 1")
|
||||
service_2 = create_service(service_name="service 2")
|
||||
create_service_data_retention(
|
||||
service=service_1, notification_type=SMS_TYPE, days_of_retention=3
|
||||
service=service_1, notification_type=NotificationType.SMS, days_of_retention=3
|
||||
)
|
||||
create_service_data_retention(
|
||||
service=service_2, notification_type=EMAIL_TYPE, days_of_retention=30
|
||||
service=service_2, notification_type=NotificationType.EMAIL, days_of_retention=30
|
||||
)
|
||||
sms_template_service_1 = create_template(service=service_1)
|
||||
email_template_service_1 = create_template(service=service_1, template_type="email")
|
||||
|
||||
@@ -14,15 +14,14 @@ from app.celery.reporting_tasks import (
|
||||
from app.config import QueueNames
|
||||
from app.dao.fact_billing_dao import get_rate
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_TYPES,
|
||||
SMS_TYPE,
|
||||
FactBilling,
|
||||
FactNotificationStatus,
|
||||
Notification,
|
||||
NotificationType,
|
||||
)
|
||||
from tests.app.db import (
|
||||
create_notification,
|
||||
@@ -36,9 +35,9 @@ from tests.app.db import (
|
||||
def mocker_get_rate(
|
||||
non_letter_rates, notification_type, local_date, rate_multiplier=None
|
||||
):
|
||||
if notification_type == SMS_TYPE:
|
||||
if notification_type == NotificationType.SMS:
|
||||
return Decimal(1.33)
|
||||
elif notification_type == EMAIL_TYPE:
|
||||
elif notification_type == NotificationType.EMAIL:
|
||||
return Decimal(0)
|
||||
|
||||
|
||||
@@ -83,7 +82,7 @@ def test_create_nightly_notification_status_triggers_tasks(
|
||||
kwargs={
|
||||
"service_id": sample_service.id,
|
||||
"process_day": "2019-07-31",
|
||||
"notification_type": SMS_TYPE,
|
||||
"notification_type": NotificationType.SMS,
|
||||
},
|
||||
queue=QueueNames.REPORTING,
|
||||
)
|
||||
@@ -94,8 +93,8 @@ def test_create_nightly_notification_status_triggers_tasks(
|
||||
"notification_date, expected_types_aggregated",
|
||||
[
|
||||
("2019-08-01", set()),
|
||||
("2019-07-31", {EMAIL_TYPE, SMS_TYPE}),
|
||||
("2019-07-28", {EMAIL_TYPE, SMS_TYPE}),
|
||||
("2019-07-31", {NotificationType.EMAIL, NotificationType.SMS}),
|
||||
("2019-07-28", {NotificationType.EMAIL, NotificationType.SMS}),
|
||||
("2019-07-21", set()),
|
||||
],
|
||||
)
|
||||
@@ -148,7 +147,7 @@ def test_create_nightly_billing_for_day_checks_history(
|
||||
assert len(records) == 1
|
||||
|
||||
record = records[0]
|
||||
assert record.notification_type == SMS_TYPE
|
||||
assert record.notification_type == NotificationType.SMS
|
||||
assert record.notifications_sent == 2
|
||||
|
||||
|
||||
@@ -321,14 +320,14 @@ def test_create_nightly_billing_for_day_null_sent_by_sms(
|
||||
|
||||
def test_get_rate_for_sms_and_email(notify_db_session):
|
||||
non_letter_rates = [
|
||||
create_rate(datetime(2017, 12, 1), 0.15, SMS_TYPE),
|
||||
create_rate(datetime(2017, 12, 1), 0, EMAIL_TYPE),
|
||||
create_rate(datetime(2017, 12, 1), 0.15, NotificationType.SMS),
|
||||
create_rate(datetime(2017, 12, 1), 0, NotificationType.EMAIL),
|
||||
]
|
||||
|
||||
rate = get_rate(non_letter_rates, SMS_TYPE, date(2018, 1, 1))
|
||||
rate = get_rate(non_letter_rates, NotificationType.SMS, date(2018, 1, 1))
|
||||
assert rate == Decimal(0.15)
|
||||
|
||||
rate = get_rate(non_letter_rates, EMAIL_TYPE, date(2018, 1, 1))
|
||||
rate = get_rate(non_letter_rates, NotificationType.EMAIL, date(2018, 1, 1))
|
||||
assert rate == Decimal(0)
|
||||
|
||||
|
||||
|
||||
@@ -30,15 +30,15 @@ from app.celery.tasks import (
|
||||
from app.config import QueueNames
|
||||
from app.dao import jobs_dao, service_email_reply_to_dao, service_sms_sender_dao
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
JOB_STATUS_ERROR,
|
||||
JOB_STATUS_FINISHED,
|
||||
JOB_STATUS_IN_PROGRESS,
|
||||
KEY_TYPE_NORMAL,
|
||||
NOTIFICATION_CREATED,
|
||||
SMS_TYPE,
|
||||
Job,
|
||||
Notification,
|
||||
NotificationType,
|
||||
TemplateType,
|
||||
)
|
||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
||||
from app.utils import DATETIME_FORMAT
|
||||
@@ -305,8 +305,8 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template, mock
|
||||
@pytest.mark.parametrize(
|
||||
"template_type, expected_function, expected_queue",
|
||||
[
|
||||
(SMS_TYPE, "save_sms", "database-tasks"),
|
||||
(EMAIL_TYPE, "save_email", "database-tasks"),
|
||||
(TemplateType.SMS, "save_sms", "database-tasks"),
|
||||
(TemplateType.EMAIL, "save_email", "database-tasks"),
|
||||
],
|
||||
)
|
||||
def test_process_row_sends_letter_task(
|
||||
@@ -362,7 +362,7 @@ def test_process_row_when_sender_id_is_provided(mocker, fake_uuid):
|
||||
mocker.patch("app.celery.tasks.create_uuid", return_value="noti_uuid")
|
||||
task_mock = mocker.patch("app.celery.tasks.save_sms.apply_async")
|
||||
encrypt_mock = mocker.patch("app.celery.tasks.encryption.encrypt")
|
||||
template = Mock(id="template_id", template_type=SMS_TYPE)
|
||||
template = Mock(id="template_id", template_type=TemplateType.SMS)
|
||||
job = Mock(id="job_id", template_version="temp_vers")
|
||||
service = Mock(id="service_id", research_mode=False)
|
||||
|
||||
@@ -1384,8 +1384,8 @@ def test_process_incomplete_jobs_sets_status_to_in_progress_and_resets_processin
|
||||
def test_save_api_email_or_sms(mocker, sample_service, notification_type):
|
||||
template = (
|
||||
create_template(sample_service)
|
||||
if notification_type == SMS_TYPE
|
||||
else create_template(sample_service, template_type=EMAIL_TYPE)
|
||||
if notification_type == NotificationType.SMS
|
||||
else create_template(sample_service, template_type=TemplateType.EMAIL)
|
||||
)
|
||||
mock_provider_task = mocker.patch(
|
||||
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
|
||||
@@ -1407,7 +1407,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
|
||||
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
|
||||
if notification_type == EMAIL_TYPE:
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
data.update({"to": "jane.citizen@example.com"})
|
||||
expected_queue = QueueNames.SEND_EMAIL
|
||||
else:
|
||||
@@ -1417,7 +1417,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
|
||||
encrypted = encryption.encrypt(data)
|
||||
|
||||
assert len(Notification.query.all()) == 0
|
||||
if notification_type == EMAIL_TYPE:
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
save_api_email(encrypted_notification=encrypted)
|
||||
else:
|
||||
save_api_sms(encrypted_notification=encrypted)
|
||||
@@ -1436,8 +1436,8 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
|
||||
):
|
||||
template = (
|
||||
create_template(sample_service)
|
||||
if notification_type == SMS_TYPE
|
||||
else create_template(sample_service, template_type=EMAIL_TYPE)
|
||||
if notification_type == NotificationType.SMS
|
||||
else create_template(sample_service, template_type=TemplateType.EMAIL)
|
||||
)
|
||||
mock_provider_task = mocker.patch(
|
||||
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
|
||||
@@ -1459,7 +1459,7 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
|
||||
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
|
||||
if notification_type == EMAIL_TYPE:
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
data.update({"to": "jane.citizen@example.com"})
|
||||
expected_queue = QueueNames.SEND_EMAIL
|
||||
else:
|
||||
@@ -1469,14 +1469,14 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
|
||||
encrypted = encryption.encrypt(data)
|
||||
assert len(Notification.query.all()) == 0
|
||||
|
||||
if notification_type == EMAIL_TYPE:
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
save_api_email(encrypted_notification=encrypted)
|
||||
else:
|
||||
save_api_sms(encrypted_notification=encrypted)
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
# call the task again with the same notification
|
||||
if notification_type == EMAIL_TYPE:
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
save_api_email(encrypted_notification=encrypted)
|
||||
else:
|
||||
save_api_sms(encrypted_notification=encrypted)
|
||||
|
||||
Reference in New Issue
Block a user