mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
@@ -99,7 +99,7 @@ def test_send_notification_invalid_template_id(
|
|||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
mocked = mocker.patch(
|
mocked = mocker.patch(
|
||||||
"app.celery.provider_tasks.deliver_{}.apply_async".format(template_type)
|
f"app.celery.provider_tasks.deliver_{template_type}.apply_async"
|
||||||
)
|
)
|
||||||
|
|
||||||
data = {"to": to, "template": fake_uuid}
|
data = {"to": to, "template": fake_uuid}
|
||||||
@@ -108,7 +108,7 @@ def test_send_notification_invalid_template_id(
|
|||||||
)
|
)
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path="/notifications/{}".format(template_type),
|
path=f"/notifications/{template_type}",
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
@@ -653,7 +653,7 @@ def test_should_send_sms_to_anyone_with_test_key(
|
|||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[
|
headers=[
|
||||||
("Content-Type", "application/json"),
|
("Content-Type", "application/json"),
|
||||||
("Authorization", "Bearer {}".format(auth_header)),
|
("Authorization", f"Bearer {auth_header}"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with(
|
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with(
|
||||||
@@ -691,7 +691,7 @@ def test_should_send_email_to_anyone_with_test_key(
|
|||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[
|
headers=[
|
||||||
("Content-Type", "application/json"),
|
("Content-Type", "application/json"),
|
||||||
("Authorization", "Bearer {}".format(auth_header)),
|
("Authorization", f"Bearer {auth_header}"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -756,7 +756,7 @@ def test_should_persist_notification(
|
|||||||
queue_name,
|
queue_name,
|
||||||
):
|
):
|
||||||
mocked = mocker.patch(
|
mocked = mocker.patch(
|
||||||
"app.celery.provider_tasks.deliver_{}.apply_async".format(template_type)
|
f"app.celery.provider_tasks.deliver_{template_type}.apply_async"
|
||||||
)
|
)
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"app.notifications.process_notifications.uuid.uuid4", return_value=fake_uuid
|
"app.notifications.process_notifications.uuid.uuid4", return_value=fake_uuid
|
||||||
@@ -843,11 +843,11 @@ def test_should_delete_notification_and_return_error_if_redis_fails(
|
|||||||
|
|
||||||
with pytest.raises(expected_exception=Exception) as e:
|
with pytest.raises(expected_exception=Exception) as e:
|
||||||
client.post(
|
client.post(
|
||||||
path="/notifications/{}".format(template_type),
|
path=f"/notifications/{template_type}",
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[
|
headers=[
|
||||||
("Content-Type", "application/json"),
|
("Content-Type", "application/json"),
|
||||||
("Authorization", "Bearer {}".format(auth_header)),
|
("Authorization", f"Bearer {auth_header}"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
assert str(e.value) == "failed to talk to redis"
|
assert str(e.value) == "failed to talk to redis"
|
||||||
@@ -926,7 +926,7 @@ def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode(
|
|||||||
service.message_limit = 2
|
service.message_limit = 2
|
||||||
|
|
||||||
apply_async = mocker.patch(
|
apply_async = mocker.patch(
|
||||||
"app.celery.provider_tasks.deliver_{}.apply_async".format(notification_type)
|
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
|
||||||
)
|
)
|
||||||
template = create_template(service, template_type=notification_type)
|
template = create_template(service, template_type=notification_type)
|
||||||
assert sample_service_guest_list.service_id == service.id
|
assert sample_service_guest_list.service_id == service.id
|
||||||
@@ -946,7 +946,7 @@ def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode(
|
|||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[
|
headers=[
|
||||||
("Content-Type", "application/json"),
|
("Content-Type", "application/json"),
|
||||||
("Authorization", "Bearer {}".format(auth_header)),
|
("Authorization", f"Bearer {auth_header}"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -989,7 +989,7 @@ def test_should_send_notification_to_guest_list_recipient(
|
|||||||
sample_service.restricted = service_restricted
|
sample_service.restricted = service_restricted
|
||||||
|
|
||||||
apply_async = mocker.patch(
|
apply_async = mocker.patch(
|
||||||
"app.celery.provider_tasks.deliver_{}.apply_async".format(notification_type)
|
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
|
||||||
)
|
)
|
||||||
template = create_template(sample_service, template_type=notification_type)
|
template = create_template(sample_service, template_type=notification_type)
|
||||||
if notification_type == NotificationType.SMS:
|
if notification_type == NotificationType.SMS:
|
||||||
@@ -1016,7 +1016,7 @@ def test_should_send_notification_to_guest_list_recipient(
|
|||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[
|
headers=[
|
||||||
("Content-Type", "application/json"),
|
("Content-Type", "application/json"),
|
||||||
("Authorization", "Bearer {}".format(auth_header)),
|
("Authorization", f"Bearer {auth_header}"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1119,7 +1119,14 @@ def test_create_template_raises_invalid_request_when_content_too_large(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"notification_type, send_to", [("sms", "2028675309"), ("email", "sample@email.com")]
|
"notification_type,send_to",
|
||||||
|
[
|
||||||
|
(NotificationType.SMS, "2028675309"),
|
||||||
|
(
|
||||||
|
NotificationType.EMAIL,
|
||||||
|
"sample@email.com",
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority(
|
def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority(
|
||||||
client,
|
client,
|
||||||
@@ -1132,7 +1139,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
|
|||||||
sample_service, template_type=notification_type, process_type="priority"
|
sample_service, template_type=notification_type, process_type="priority"
|
||||||
)
|
)
|
||||||
mocked = mocker.patch(
|
mocked = mocker.patch(
|
||||||
"app.celery.provider_tasks.deliver_{}.apply_async".format(notification_type)
|
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
|
||||||
)
|
)
|
||||||
|
|
||||||
data = {"to": send_to, "template": str(sample.id)}
|
data = {"to": send_to, "template": str(sample.id)}
|
||||||
@@ -1140,7 +1147,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
|
|||||||
auth_header = create_service_authorization_header(service_id=sample.service_id)
|
auth_header = create_service_authorization_header(service_id=sample.service_id)
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path="/notifications/{}".format(notification_type),
|
path=f"/notifications/{notification_type}",
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
@@ -1153,7 +1160,14 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"notification_type, send_to", [("sms", "2028675309"), ("email", "sample@email.com")]
|
"notification_type, send_to",
|
||||||
|
[
|
||||||
|
(NotificationType.SMS, "2028675309"),
|
||||||
|
(
|
||||||
|
NotificationType.EMAIL,
|
||||||
|
"sample@email.com",
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
||||||
client, sample_service, mocker, notification_type, send_to
|
client, sample_service, mocker, notification_type, send_to
|
||||||
@@ -1172,7 +1186,7 @@ def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
|||||||
auth_header = create_service_authorization_header(service_id=sample.service_id)
|
auth_header = create_service_authorization_header(service_id=sample.service_id)
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path="/notifications/{}".format(notification_type),
|
path=f"/notifications/{notification_type}",
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
@@ -1181,9 +1195,9 @@ def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
|||||||
result = json.loads(response.data)["result"]
|
result = json.loads(response.data)["result"]
|
||||||
assert response.status_code == 429
|
assert response.status_code == 429
|
||||||
assert result == "error"
|
assert result == "error"
|
||||||
assert (
|
assert message == (
|
||||||
message
|
"Exceeded rate limit for key type TYPE of LIMIT "
|
||||||
== "Exceeded rate limit for key type TYPE of LIMIT requests per INTERVAL seconds"
|
"requests per INTERVAL seconds"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert not persist_mock.called
|
assert not persist_mock.called
|
||||||
@@ -1332,7 +1346,7 @@ def test_should_throw_exception_if_notification_type_is_invalid(
|
|||||||
):
|
):
|
||||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path="/notifications/{}".format(notification_type),
|
path=f"/notifications/{notification_type}",
|
||||||
data={},
|
data={},
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
@@ -1341,14 +1355,19 @@ def test_should_throw_exception_if_notification_type_is_invalid(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"notification_type, recipient", [("sms", "2028675309"), ("email", "test@gov.uk")]
|
"notification_type, recipient",
|
||||||
|
[
|
||||||
|
(NotificationType.SMS, "2028675309"),
|
||||||
|
(
|
||||||
|
NotificationType.EMAIL,
|
||||||
|
"test@gov.uk",
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_post_notification_should_set_reply_to_text(
|
def test_post_notification_should_set_reply_to_text(
|
||||||
client, sample_service, mocker, notification_type, recipient
|
client, sample_service, mocker, notification_type, recipient
|
||||||
):
|
):
|
||||||
mocker.patch(
|
mocker.patch(f"app.celery.provider_tasks.deliver_{notification_type}.apply_async")
|
||||||
"app.celery.provider_tasks.deliver_{}.apply_async".format(notification_type)
|
|
||||||
)
|
|
||||||
template = create_template(sample_service, template_type=notification_type)
|
template = create_template(sample_service, template_type=notification_type)
|
||||||
expected_reply_to = current_app.config["FROM_NUMBER"]
|
expected_reply_to = current_app.config["FROM_NUMBER"]
|
||||||
if notification_type == NotificationType.EMAIL:
|
if notification_type == NotificationType.EMAIL:
|
||||||
@@ -1359,7 +1378,7 @@ def test_post_notification_should_set_reply_to_text(
|
|||||||
|
|
||||||
data = {"to": recipient, "template": str(template.id)}
|
data = {"to": recipient, "template": str(template.id)}
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/notifications/{}".format(notification_type),
|
f"/notifications/{notification_type}",
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[
|
headers=[
|
||||||
("Content-Type", "application/json"),
|
("Content-Type", "application/json"),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from app.enums import (
|
|||||||
KeyType,
|
KeyType,
|
||||||
NotificationType,
|
NotificationType,
|
||||||
RecipientType,
|
RecipientType,
|
||||||
|
ServicePermissionType,
|
||||||
TemplateProcessType,
|
TemplateProcessType,
|
||||||
TemplateType,
|
TemplateType,
|
||||||
)
|
)
|
||||||
@@ -100,7 +101,12 @@ def test_send_one_off_notification_calls_persist_correctly_for_sms(
|
|||||||
def test_send_one_off_notification_calls_persist_correctly_for_international_sms(
|
def test_send_one_off_notification_calls_persist_correctly_for_international_sms(
|
||||||
persist_mock, celery_mock, notify_db_session
|
persist_mock, celery_mock, notify_db_session
|
||||||
):
|
):
|
||||||
service = create_service(service_permissions=["sms", "international_sms"])
|
service = create_service(
|
||||||
|
service_permissions=[
|
||||||
|
ServicePermissionType.SMS,
|
||||||
|
ServicePermissionType.INTERNATIONAL_SMS,
|
||||||
|
],
|
||||||
|
)
|
||||||
template = create_template(
|
template = create_template(
|
||||||
service=service,
|
service=service,
|
||||||
template_type=TemplateType.SMS,
|
template_type=TemplateType.SMS,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from freezegun import freeze_time
|
|||||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||||
|
|
||||||
from app.dao.templates_dao import dao_get_template_by_id, dao_redact_template
|
from app.dao.templates_dao import dao_get_template_by_id, dao_redact_template
|
||||||
from app.enums import ServicePermissionType, TemplateType
|
from app.enums import ServicePermissionType, TemplateProcessType, TemplateType
|
||||||
from app.models import Template, TemplateHistory
|
from app.models import Template, TemplateHistory
|
||||||
from tests import create_admin_authorization_header
|
from tests import create_admin_authorization_header
|
||||||
from tests.app.db import create_service, create_template, create_template_folder
|
from tests.app.db import create_service, create_template, create_template_folder
|
||||||
@@ -39,7 +39,7 @@ def test_should_create_a_new_template_for_a_service(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(service.id),
|
f"/service/{service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -51,7 +51,7 @@ def test_should_create_a_new_template_for_a_service(
|
|||||||
assert json_resp["data"]["service"] == str(service.id)
|
assert json_resp["data"]["service"] == str(service.id)
|
||||||
assert json_resp["data"]["id"]
|
assert json_resp["data"]["id"]
|
||||||
assert json_resp["data"]["version"] == 1
|
assert json_resp["data"]["version"] == 1
|
||||||
assert json_resp["data"]["process_type"] == "normal"
|
assert json_resp["data"]["process_type"] == TemplateProcessType.NORMAL
|
||||||
assert json_resp["data"]["created_by"] == str(sample_user.id)
|
assert json_resp["data"]["created_by"] == str(sample_user.id)
|
||||||
if subject:
|
if subject:
|
||||||
assert json_resp["data"]["subject"] == "subject"
|
assert json_resp["data"]["subject"] == "subject"
|
||||||
@@ -71,7 +71,7 @@ def test_create_a_new_template_for_a_service_adds_folder_relationship(
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
"name": "my template",
|
"name": "my template",
|
||||||
"template_type": "sms",
|
"template_type": TemplateType.SMS,
|
||||||
"content": "template <b>content</b>",
|
"content": "template <b>content</b>",
|
||||||
"service": str(sample_service.id),
|
"service": str(sample_service.id),
|
||||||
"created_by": str(sample_service.users[0].id),
|
"created_by": str(sample_service.users[0].id),
|
||||||
@@ -81,7 +81,7 @@ def test_create_a_new_template_for_a_service_adds_folder_relationship(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(sample_service.id),
|
f"/service/{sample_service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -98,7 +98,7 @@ def test_create_template_should_return_400_if_folder_is_for_a_different_service(
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
"name": "my template",
|
"name": "my template",
|
||||||
"template_type": "sms",
|
"template_type": TemplateType.SMS,
|
||||||
"content": "template <b>content</b>",
|
"content": "template <b>content</b>",
|
||||||
"service": str(sample_service.id),
|
"service": str(sample_service.id),
|
||||||
"created_by": str(sample_service.users[0].id),
|
"created_by": str(sample_service.users[0].id),
|
||||||
@@ -108,7 +108,7 @@ def test_create_template_should_return_400_if_folder_is_for_a_different_service(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(sample_service.id),
|
f"/service/{sample_service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -124,7 +124,7 @@ def test_create_template_should_return_400_if_folder_does_not_exist(
|
|||||||
):
|
):
|
||||||
data = {
|
data = {
|
||||||
"name": "my template",
|
"name": "my template",
|
||||||
"template_type": "sms",
|
"template_type": TemplateType.SMS,
|
||||||
"content": "template <b>content</b>",
|
"content": "template <b>content</b>",
|
||||||
"service": str(sample_service.id),
|
"service": str(sample_service.id),
|
||||||
"created_by": str(sample_service.users[0].id),
|
"created_by": str(sample_service.users[0].id),
|
||||||
@@ -134,7 +134,7 @@ def test_create_template_should_return_400_if_folder_does_not_exist(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(sample_service.id),
|
f"/service/{sample_service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -159,7 +159,7 @@ def test_should_raise_error_if_service_does_not_exist_on_create(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(fake_uuid),
|
f"/service/{fake_uuid}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -204,7 +204,7 @@ def test_should_raise_error_on_create_if_no_permission(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(service.id),
|
f"/service/{service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -245,9 +245,7 @@ def test_should_be_error_on_update_if_no_permission(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
update_response = client.post(
|
update_response = client.post(
|
||||||
"/service/{}/template/{}".format(
|
f"/service/{template_without_permission.service_id}/template/{template_without_permission.id}",
|
||||||
template_without_permission.service_id, template_without_permission.id
|
|
||||||
),
|
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -270,7 +268,7 @@ def test_should_error_if_created_by_missing(client, sample_user, sample_service)
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(service_id),
|
f"/service/{service_id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -286,7 +284,7 @@ def test_should_be_error_if_service_does_not_exist_on_update(client, fake_uuid):
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template/{}".format(fake_uuid, fake_uuid),
|
f"/service/{fake_uuid}/template/{fake_uuid}",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -322,7 +320,7 @@ def test_must_have_a_subject_on_an_email_template(
|
|||||||
|
|
||||||
def test_update_should_update_a_template(client, sample_user):
|
def test_update_should_update_a_template(client, sample_user):
|
||||||
service = create_service()
|
service = create_service()
|
||||||
template = create_template(service, template_type="sms")
|
template = create_template(service, template_type=TemplateType.SMS)
|
||||||
|
|
||||||
assert template.created_by == service.created_by
|
assert template.created_by == service.created_by
|
||||||
assert template.created_by != sample_user
|
assert template.created_by != sample_user
|
||||||
@@ -335,7 +333,7 @@ def test_update_should_update_a_template(client, sample_user):
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
update_response = client.post(
|
update_response = client.post(
|
||||||
"/service/{}/template/{}".format(service.id, template.id),
|
f"/service/{service.id}/template/{template.id}",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -373,9 +371,7 @@ def test_should_be_able_to_archive_template(client, sample_template):
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/service/{}/template/{}".format(
|
f"/service/{sample_template.service.id}/template/{sample_template.id}",
|
||||||
sample_template.service.id, sample_template.id
|
|
||||||
),
|
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=json_data,
|
data=json_data,
|
||||||
)
|
)
|
||||||
@@ -431,14 +427,14 @@ def test_should_be_able_to_get_all_templates_for_a_service(
|
|||||||
data_2 = json.dumps(data)
|
data_2 = json.dumps(data)
|
||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
client.post(
|
client.post(
|
||||||
"/service/{}/template".format(sample_service.id),
|
f"/service/{sample_service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data_1,
|
data=data_1,
|
||||||
)
|
)
|
||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
client.post(
|
client.post(
|
||||||
"/service/{}/template".format(sample_service.id),
|
f"/service/{sample_service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data_2,
|
data=data_2,
|
||||||
)
|
)
|
||||||
@@ -446,7 +442,7 @@ def test_should_be_able_to_get_all_templates_for_a_service(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
"/service/{}/template".format(sample_service.id), headers=[auth_header]
|
f"/service/{sample_service.id}/template", headers=[auth_header]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
@@ -467,10 +463,12 @@ def test_should_get_only_templates_for_that_service(admin_request, notify_db_ses
|
|||||||
id_3 = create_template(service_2).id
|
id_3 = create_template(service_2).id
|
||||||
|
|
||||||
json_resp_1 = admin_request.get(
|
json_resp_1 = admin_request.get(
|
||||||
"template.get_all_templates_for_service", service_id=service_1.id
|
"template.get_all_templates_for_service",
|
||||||
|
service_id=service_1.id,
|
||||||
)
|
)
|
||||||
json_resp_2 = admin_request.get(
|
json_resp_2 = admin_request.get(
|
||||||
"template.get_all_templates_for_service", service_id=service_2.id
|
"template.get_all_templates_for_service",
|
||||||
|
service_id=service_2.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert {template["id"] for template in json_resp_1["data"]} == {
|
assert {template["id"] for template in json_resp_1["data"]} == {
|
||||||
@@ -580,7 +578,7 @@ def test_should_get_a_single_template(
|
|||||||
)
|
)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
"/service/{}/template/{}".format(sample_service.id, template.id),
|
f"/service/{sample_service.id}/template/{template.id}",
|
||||||
headers=[create_admin_authorization_header()],
|
headers=[create_admin_authorization_header()],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -667,7 +665,7 @@ def test_should_return_empty_array_if_no_templates_for_service(client, sample_se
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
"/service/{}/template".format(sample_service.id), headers=[auth_header]
|
f"/service/{sample_service.id}/template", headers=[auth_header]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
@@ -681,7 +679,7 @@ def test_should_return_404_if_no_templates_for_service_with_id(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
"/service/{}/template/{}".format(sample_service.id, fake_uuid),
|
f"/service/{sample_service.id}/template/{fake_uuid}",
|
||||||
headers=[auth_header],
|
headers=[auth_header],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -715,7 +713,7 @@ def test_create_400_for_over_limit_content(
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/service/{}/template".format(sample_service.id),
|
f"/service/{sample_service.id}/template",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
@@ -740,9 +738,7 @@ def test_update_400_for_over_limit_content(
|
|||||||
)
|
)
|
||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/service/{}/template/{}".format(
|
f"/service/{sample_template.service.id}/template/{sample_template.id}",
|
||||||
sample_template.service.id, sample_template.id
|
|
||||||
),
|
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
data=json_data,
|
data=json_data,
|
||||||
)
|
)
|
||||||
@@ -766,9 +762,7 @@ def test_should_return_all_template_versions_for_service_and_template_id(
|
|||||||
|
|
||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
resp = client.get(
|
resp = client.get(
|
||||||
"/service/{}/template/{}/versions".format(
|
f"/service/{sample_template.service_id}/template/{sample_template.id}/versions",
|
||||||
sample_template.service_id, sample_template.id
|
|
||||||
),
|
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
@@ -792,9 +786,7 @@ def test_update_does_not_create_new_version_when_there_is_no_change(
|
|||||||
"content": sample_template.content,
|
"content": sample_template.content,
|
||||||
}
|
}
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/service/{}/template/{}".format(
|
f"/service/{sample_template.service_id}/template/{sample_template.id}",
|
||||||
sample_template.service_id, sample_template.id
|
|
||||||
),
|
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
@@ -808,9 +800,7 @@ def test_update_set_process_type_on_template(client, sample_template):
|
|||||||
auth_header = create_admin_authorization_header()
|
auth_header = create_admin_authorization_header()
|
||||||
data = {"process_type": "priority"}
|
data = {"process_type": "priority"}
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/service/{}/template/{}".format(
|
f"/service/{sample_template.service_id}/template/{sample_template.id}",
|
||||||
sample_template.service_id, sample_template.id
|
|
||||||
),
|
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from unittest.mock import Mock
|
|||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
||||||
|
from app.enums import NotificationStatus, TemplateType
|
||||||
from app.utils import DATETIME_FORMAT
|
from app.utils import DATETIME_FORMAT
|
||||||
from tests.app.db import create_ft_notification_status, create_notification
|
from tests.app.db import create_ft_notification_status, create_notification
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ def test_get_template_statistics_for_service_by_day_returns_template_info(
|
|||||||
assert json_resp["data"][0]["count"] == 1
|
assert json_resp["data"][0]["count"] == 1
|
||||||
assert json_resp["data"][0]["template_id"] == str(sample_notification.template_id)
|
assert json_resp["data"][0]["template_id"] == str(sample_notification.template_id)
|
||||||
assert json_resp["data"][0]["template_name"] == "sms Template Name"
|
assert json_resp["data"][0]["template_name"] == "sms Template Name"
|
||||||
assert json_resp["data"][0]["template_type"] == "sms"
|
assert json_resp["data"][0]["template_type"] == TemplateType.SMS
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("var_name", ["limit_days", "whole_days"])
|
@pytest.mark.parametrize("var_name", ["limit_days", "whole_days"])
|
||||||
@@ -77,7 +78,7 @@ def test_get_template_statistics_for_service_by_day_goes_to_db(
|
|||||||
count=3,
|
count=3,
|
||||||
template_name=sample_template.name,
|
template_name=sample_template.name,
|
||||||
notification_type=sample_template.template_type,
|
notification_type=sample_template.template_type,
|
||||||
status="created",
|
status=NotificationStatus.CREATED,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -93,7 +94,7 @@ def test_get_template_statistics_for_service_by_day_goes_to_db(
|
|||||||
"count": 3,
|
"count": 3,
|
||||||
"template_name": sample_template.name,
|
"template_name": sample_template.name,
|
||||||
"template_type": sample_template.template_type,
|
"template_type": sample_template.template_type,
|
||||||
"status": "created",
|
"status": NotificationStatus.CREATED,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
# dao only called for 2nd, since redis returned values for first call
|
# dao only called for 2nd, since redis returned values for first call
|
||||||
|
|||||||
Reference in New Issue
Block a user