String cleanup complete.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-21 14:50:36 -05:00
parent 7083db9351
commit 06d1e0236f
15 changed files with 67 additions and 54 deletions

View File

@@ -20,7 +20,7 @@ from app.dao.service_callback_api_dao import (
get_service_complaint_callback_api_for_service,
get_service_delivery_status_callback_api_for_service,
)
from app.enums import NotificationStatus
from app.enums import CallbackType, NotificationStatus
from app.models import Complaint
@@ -209,7 +209,7 @@ def handle_complaint(ses_message):
)
return
notification = dao_get_notification_history_by_reference(reference)
ses_complaint = ses_message.get("complaint", None)
ses_complaint = ses_message.get(CallbackType.COMPLAINT, None)
complaint = Complaint(
notification_id=notification.id,
@@ -241,7 +241,7 @@ def remove_emails_from_bounce(bounce_dict):
def remove_emails_from_complaint(complaint_dict):
remove_mail_headers(complaint_dict)
complaint_dict["complaint"].pop("complainedRecipients")
complaint_dict[CallbackType.COMPLAINT].pop("complainedRecipients")
return complaint_dict["mail"].pop("destination")

View File

@@ -3,6 +3,7 @@ from flask import current_app
from app import db
from app.dao.dao_utils import autocommit
from app.dao.date_util import get_current_calendar_year_start_year
from app.enums import OrganizationType
from app.models import AnnualBilling
@@ -65,17 +66,17 @@ def dao_get_all_free_sms_fragment_limit(service_id):
def set_default_free_allowance_for_service(service, year_start=None):
default_free_sms_fragment_limits = {
"federal": {
OrganizationType.FEDERAL: {
2020: 250_000,
2021: 150_000,
2022: 40_000,
},
"state": {
OrganizationType.STATE: {
2020: 250_000,
2021: 150_000,
2022: 40_000,
},
"other": {
OrganizationType.OTHER: {
2020: 250_000,
2021: 150_000,
2022: 40_000,
@@ -97,7 +98,9 @@ def set_default_free_allowance_for_service(service, year_start=None):
f"no organization type for service {service.id}. Using other default of "
f"{default_free_sms_fragment_limits['other'][year_start]}"
)
free_allowance = default_free_sms_fragment_limits["other"][year_start]
free_allowance = default_free_sms_fragment_limits[OrganizationType.OTHER][
year_start
]
return dao_create_or_update_annual_billing_for_year(
service.id, free_allowance, year_start

View File

@@ -16,7 +16,7 @@ from app.celery.test_key_tasks import (
ses_soft_bounce_callback,
)
from app.dao.notifications_dao import get_notification_by_id
from app.enums import NotificationStatus
from app.enums import CallbackType, NotificationStatus
from app.models import Complaint
from tests.app.conftest import create_sample_notification
from tests.app.db import (
@@ -407,7 +407,7 @@ def test_ses_callback_should_send_on_complaint_to_user_callback_api(
create_service_callback_api(
service=sample_email_template.service,
url="https://original_url.com",
callback_type="complaint",
callback_type=CallbackType.COMPLAINT,
)
notification = create_notification(
template=sample_email_template,

View File

@@ -27,7 +27,10 @@ from tests.app.db import (
def test_send_delivery_status_to_service_post_https_request_to_service_with_encrypted_data(
notify_db_session, notification_type
):
callback_api, template = _set_up_test_data(notification_type, "delivery_status")
callback_api, template = _set_up_test_data(
notification_type,
CallbackType.DELIVERY_STATUS,
)
datestr = datetime(2017, 6, 20)
notification = create_notification(

View File

@@ -67,17 +67,17 @@ def test_dao_update_annual_billing_for_future_years(notify_db_session, sample_se
@pytest.mark.parametrize(
"org_type, year, expected_default",
[
("federal", 2021, 150000),
("state", 2021, 150000),
(OrganizationType.FEDERAL, 2021, 150000),
(OrganizationType.STATE, 2021, 150000),
(None, 2021, 150000),
("federal", 2020, 250000),
("state", 2020, 250000),
("other", 2020, 250000),
(OrganizationType.FEDERAL, 2020, 250000),
(OrganizationType.STATE, 2020, 250000),
(OrganizationType.OTHER, 2020, 250000),
(None, 2020, 250000),
("federal", 2019, 250000),
("federal", 2022, 40000),
("state", 2022, 40000),
("federal", 2023, 40000),
(OrganizationType.FEDERAL, 2019, 250000),
(OrganizationType.FEDERAL, 2022, 40000),
(OrganizationType.STATE, 2022, 40000),
(OrganizationType.FEDERAL, 2023, 40000),
],
)
def test_set_default_free_allowance_for_service(

View File

@@ -10,6 +10,7 @@ from app.dao.service_callback_api_dao import (
reset_service_callback_api,
save_service_callback_api,
)
from app.enums import CallbackType
from app.models import ServiceCallbackApi
from tests.app.db import create_service_callback_api
@@ -65,7 +66,7 @@ def test_update_service_callback_api_unique_constraint(sample_service):
url="https://some_service/callback_endpoint",
bearer_token="some_unique_string",
updated_by_id=sample_service.users[0].id,
callback_type="delivery_status",
callback_type=CallbackType.DELIVERY_STATUS,
)
save_service_callback_api(service_callback_api)
another = ServiceCallbackApi(
@@ -73,7 +74,7 @@ def test_update_service_callback_api_unique_constraint(sample_service):
url="https://some_service/another_callback_endpoint",
bearer_token="different_string",
updated_by_id=sample_service.users[0].id,
callback_type="delivery_status",
callback_type=CallbackType.DELIVERY_STATUS,
)
with pytest.raises(expected_exception=SQLAlchemyError):
save_service_callback_api(another)
@@ -85,7 +86,7 @@ def test_update_service_callback_can_add_two_api_of_different_types(sample_servi
url="https://some_service/callback_endpoint",
bearer_token="some_unique_string",
updated_by_id=sample_service.users[0].id,
callback_type="delivery_status",
callback_type=CallbackType.DELIVERY_STATUS,
)
save_service_callback_api(delivery_status)
complaint = ServiceCallbackApi(
@@ -93,7 +94,7 @@ def test_update_service_callback_can_add_two_api_of_different_types(sample_servi
url="https://some_service/another_callback_endpoint",
bearer_token="different_string",
updated_by_id=sample_service.users[0].id,
callback_type="complaint",
callback_type=CallbackType.COMPLAINT,
)
save_service_callback_api(complaint)
results = ServiceCallbackApi.query.order_by(ServiceCallbackApi.callback_type).all()

View File

@@ -27,6 +27,7 @@ from app.dao.services_dao import dao_add_user_to_service, dao_create_service
from app.dao.templates_dao import dao_create_template, dao_update_template
from app.dao.users_dao import save_model_user
from app.enums import (
CallbackType,
JobStatus,
KeyType,
NotificationStatus,
@@ -482,7 +483,7 @@ def create_service_callback_api(
service,
url="https://something.com",
bearer_token="some_super_secret",
callback_type="delivery_status",
callback_type=CallbackType.DELIVERY_STATUS,
):
service_callback_api = ServiceCallbackApi(
service_id=service.id,

View File

@@ -28,7 +28,7 @@ from tests.conftest import set_config
def test_get_job_with_invalid_service_id_returns404(client, sample_service):
path = "/service/{}/job".format(sample_service.id)
path = f"/service/{sample_service.id}/job"
auth_header = create_admin_authorization_header()
response = client.get(path, headers=[auth_header])
assert response.status_code == 200
@@ -38,7 +38,7 @@ def test_get_job_with_invalid_service_id_returns404(client, sample_service):
def test_get_job_with_invalid_job_id_returns404(client, sample_template):
service_id = sample_template.service.id
path = "/service/{}/job/{}".format(service_id, "bad-id")
path = f"/service/{service_id}/job/{'bad-id'}"
auth_header = create_admin_authorization_header()
response = client.get(path, headers=[auth_header])
assert response.status_code == 404
@@ -49,7 +49,7 @@ def test_get_job_with_invalid_job_id_returns404(client, sample_template):
def test_get_job_with_unknown_id_returns404(client, sample_template, fake_uuid):
service_id = sample_template.service.id
path = "/service/{}/job/{}".format(service_id, fake_uuid)
path = f"/service/{service_id}/job/{fake_uuid}"
auth_header = create_admin_authorization_header()
response = client.get(path, headers=[auth_header])
assert response.status_code == 404
@@ -60,7 +60,7 @@ def test_get_job_with_unknown_id_returns404(client, sample_template, fake_uuid):
def test_cancel_job(client, sample_scheduled_job):
job_id = str(sample_scheduled_job.id)
service_id = sample_scheduled_job.service.id
path = "/service/{}/job/{}/cancel".format(service_id, job_id)
path = f"/service/{service_id}/job/{job_id}/cancel"
auth_header = create_admin_authorization_header()
response = client.post(path, headers=[auth_header])
assert response.status_code == 200
@@ -73,7 +73,7 @@ def test_cant_cancel_normal_job(client, sample_job, mocker):
job_id = str(sample_job.id)
service_id = sample_job.service.id
mock_update = mocker.patch("app.dao.jobs_dao.dao_update_job")
path = "/service/{}/job/{}/cancel".format(service_id, job_id)
path = f"/service/{service_id}/job/{job_id}/cancel"
auth_header = create_admin_authorization_header()
response = client.post(path, headers=[auth_header])
assert response.status_code == 404
@@ -95,7 +95,7 @@ def test_create_unscheduled_job(client, sample_template, mocker, fake_uuid):
"id": fake_uuid,
"created_by": str(sample_template.created_by.id),
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
@@ -136,7 +136,7 @@ def test_create_unscheduled_job_with_sender_id_in_metadata(
"id": fake_uuid,
"created_by": str(sample_template.created_by.id),
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
@@ -168,7 +168,7 @@ def test_create_scheduled_job(client, sample_template, mocker, fake_uuid):
"created_by": str(sample_template.created_by.id),
"scheduled_for": scheduled_date,
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
@@ -197,7 +197,7 @@ def test_create_job_returns_403_if_service_is_not_active(
mock_job_dao = mocker.patch("app.dao.jobs_dao.dao_create_job")
auth_header = create_admin_authorization_header()
response = client.post(
"/service/{}/job".format(sample_service.id),
f"/service/{sample_service.id}/job",
data="",
headers=[("Content-Type", "application/json"), auth_header],
)
@@ -229,12 +229,12 @@ def test_create_job_returns_400_if_file_is_invalid(
template_id=str(sample_template.id),
original_file_name="thisisatest.csv",
notification_count=1,
**extra_metadata
**extra_metadata,
)
mocker.patch("app.job.rest.get_job_metadata_from_s3", return_value=metadata)
data = {"id": fake_uuid}
response = client.post(
"/service/{}/job".format(sample_template.service.id),
f"/service/{sample_template.service.id}/job",
data=json.dumps(data),
headers=[("Content-Type", "application/json"), auth_header],
)
@@ -266,7 +266,7 @@ def test_should_not_create_scheduled_job_more_then_96_hours_in_the_future(
"created_by": str(sample_template.created_by.id),
"scheduled_for": scheduled_date,
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
@@ -303,7 +303,7 @@ def test_should_not_create_scheduled_job_in_the_past(
"created_by": str(sample_template.created_by.id),
"scheduled_for": scheduled_date,
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
@@ -327,7 +327,7 @@ def test_create_job_returns_400_if_missing_id(client, sample_template, mocker):
},
)
data = {}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
response = client.post(path, data=json.dumps(data), headers=headers)
@@ -354,7 +354,7 @@ def test_create_job_returns_400_if_missing_data(
"id": fake_uuid,
"valid": "True",
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
response = client.post(path, data=json.dumps(data), headers=headers)
@@ -385,7 +385,7 @@ def test_create_job_returns_404_if_template_does_not_exist(
data = {
"id": fake_uuid,
}
path = "/service/{}/job".format(sample_service.id)
path = f"/service/{sample_service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
response = client.post(path, data=json.dumps(data), headers=headers)
@@ -408,7 +408,7 @@ def test_create_job_returns_404_if_missing_service(client, sample_template, mock
)
random_id = str(uuid.uuid4())
data = {}
path = "/service/{}/job".format(random_id)
path = f"/service/{random_id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
response = client.post(path, data=json.dumps(data), headers=headers)
@@ -437,7 +437,7 @@ def test_create_job_returns_400_if_archived_template(
"id": fake_uuid,
"valid": "True",
}
path = "/service/{}/job".format(sample_template.service.id)
path = f"/service/{sample_template.service.id}/job"
auth_header = create_admin_authorization_header()
headers = [("Content-Type", "application/json"), auth_header]
response = client.post(path, data=json.dumps(data), headers=headers)

View File

@@ -158,7 +158,7 @@ def test_get_invited_user_by_organization_when_user_does_not_belong_to_the_org(
def test_update_org_invited_user_set_status_to_cancelled(
admin_request, sample_invited_org_user
):
data = {"status": "cancelled"}
data = {"status": InvitedUserStatus.CANCELLED}
json_resp = admin_request.post(
"organization_invite.update_org_invite_status",
@@ -166,13 +166,13 @@ def test_update_org_invited_user_set_status_to_cancelled(
invited_org_user_id=sample_invited_org_user.id,
_data=data,
)
assert json_resp["data"]["status"] == "cancelled"
assert json_resp["data"]["status"] == InvitedUserStatus.CANCELLED
def test_update_org_invited_user_for_wrong_service_returns_404(
admin_request, sample_invited_org_user, fake_uuid
):
data = {"status": "cancelled"}
data = {"status": InvitedUserStatus.CANCELLED}
json_resp = admin_request.post(
"organization_invite.update_org_invite_status",

View File

@@ -580,7 +580,7 @@ def test_post_link_service_to_organization(admin_request, sample_service):
_expected_status=204,
)
assert len(organization.services) == 1
assert sample_service.organization_type == "federal"
assert sample_service.organization_type == OrganizationType.FEDERAL
@freeze_time("2021-09-24 13:30")

View File

@@ -12,7 +12,7 @@ from app.dao import notifications_dao
from app.dao.api_key_dao import save_model_api_key
from app.dao.services_dao import dao_update_service
from app.dao.templates_dao import dao_get_all_templates_for_service, dao_update_template
from app.enums import KeyType, NotificationType, TemplateType
from app.enums import KeyType, NotificationType, TemplateProcessType, TemplateType
from app.errors import InvalidRequest
from app.models import ApiKey, Notification, NotificationHistory, Template
from app.service.send_notification import send_one_off_notification
@@ -1132,7 +1132,9 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
send_to,
):
sample = create_template(
sample_service, template_type=notification_type, process_type="priority"
sample_service,
template_type=notification_type,
process_type=TemplateProcessType.PRIORITY,
)
mocked = mocker.patch(
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"

View File

@@ -229,7 +229,7 @@ def test_resend_expired_invite(
def test_update_invited_user_set_status_to_cancelled(client, sample_invited_user):
data = {"status": "cancelled"}
data = {"status": InvitedUserStatus.CANCELLED}
url = f"/service/{sample_invited_user.service_id}/invite/{sample_invited_user.id}"
auth_header = create_admin_authorization_header()
response = client.post(
@@ -246,7 +246,7 @@ def test_update_invited_user_set_status_to_cancelled(client, sample_invited_user
def test_update_invited_user_for_wrong_service_returns_404(
client, sample_invited_user, fake_uuid
):
data = {"status": "cancelled"}
data = {"status": InvitedUserStatus.CANCELLED}
url = f"/service/{fake_uuid}/invite/{sample_invited_user.id}"
auth_header = create_admin_authorization_header()
response = client.post(

View File

@@ -798,7 +798,7 @@ def test_update_does_not_create_new_version_when_there_is_no_change(
def test_update_set_process_type_on_template(client, sample_template):
auth_header = create_admin_authorization_header()
data = {"process_type": "priority"}
data = {"process_type": TemplateProcessType.PRIORITY}
resp = client.post(
f"/service/{sample_template.service_id}/template/{sample_template.id}",
data=json.dumps(data),
@@ -807,7 +807,7 @@ def test_update_set_process_type_on_template(client, sample_template):
assert resp.status_code == 200
template = dao_get_template_by_id(sample_template.id)
assert template.process_type == "priority"
assert template.process_type == TemplateProcessType.PRIORITY
@pytest.mark.parametrize(

View File

@@ -39,7 +39,7 @@ def test_template_history_version(notify_api, sample_user, sample_template):
def test_previous_template_history_version(notify_api, sample_template):
old_content = sample_template.content
sample_template.content = "New content"
sample_template.process_type = "priority"
sample_template.process_type = TemplateProcessType.PRIORITY
dao_update_template(sample_template)
with notify_api.test_request_context():
with notify_api.test_client() as client:

View File

@@ -13,6 +13,7 @@ from app.enums import (
NotificationStatus,
NotificationType,
ServicePermissionType,
TemplateProcessType,
TemplateType,
)
from app.models import Notification
@@ -580,7 +581,9 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
mocker.patch(f"app.celery.provider_tasks.deliver_{notification_type}.apply_async")
sample = create_template(
service=sample_service, template_type=notification_type, process_type="priority"
service=sample_service,
template_type=notification_type,
process_type=TemplateProcessType.PRIORITY,
)
mocked = mocker.patch(
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"