mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-28 11:49:42 -04:00
@@ -5,7 +5,7 @@ from flask import json
|
||||
from freezegun import freeze_time
|
||||
from jsonschema import ValidationError
|
||||
|
||||
from app.models import EMAIL_TYPE, NOTIFICATION_CREATED
|
||||
from app.models import NOTIFICATION_CREATED, TemplateType
|
||||
from app.schema_validation import validate
|
||||
from app.v2.notifications.notification_schemas import get_notifications_request
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
@@ -20,7 +20,7 @@ valid_get_json = {}
|
||||
valid_get_with_optionals_json = {
|
||||
"reference": "test reference",
|
||||
"status": [NOTIFICATION_CREATED],
|
||||
"template_type": [EMAIL_TYPE],
|
||||
"template_type": [TemplateType.EMAIL],
|
||||
"include_jobs": "true",
|
||||
"older_than": "a5149c32-f03b-4711-af49-ad6993797d45",
|
||||
}
|
||||
|
||||
@@ -9,11 +9,10 @@ from flask import current_app, json
|
||||
from app.dao import templates_dao
|
||||
from app.dao.service_sms_sender_dao import dao_update_service_sms_sender
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
INTERNATIONAL_SMS_TYPE,
|
||||
NOTIFICATION_CREATED,
|
||||
SMS_TYPE,
|
||||
Notification,
|
||||
NotificationType,
|
||||
ServicePermissionType,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import RateLimitError
|
||||
@@ -529,9 +528,9 @@ def test_post_email_notification_returns_201(
|
||||
@pytest.mark.parametrize(
|
||||
"recipient, notification_type",
|
||||
[
|
||||
("simulate-delivered@notifications.service.gov.uk", EMAIL_TYPE),
|
||||
("simulate-delivered-2@notifications.service.gov.uk", EMAIL_TYPE),
|
||||
("simulate-delivered-3@notifications.service.gov.uk", EMAIL_TYPE),
|
||||
("simulate-delivered@notifications.service.gov.uk", NotificationType.EMAIL),
|
||||
("simulate-delivered-2@notifications.service.gov.uk", NotificationType.EMAIL),
|
||||
("simulate-delivered-3@notifications.service.gov.uk", NotificationType.EMAIL),
|
||||
("+14254147167", "sms"),
|
||||
("+14254147755", "sms"),
|
||||
],
|
||||
@@ -655,7 +654,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_int_sms(
|
||||
client,
|
||||
notify_db_session,
|
||||
):
|
||||
service = create_service(service_permissions=[SMS_TYPE])
|
||||
service = create_service(service_permissions=[ServicePermissionType.SMS])
|
||||
template = create_template(service=service)
|
||||
|
||||
data = {"phone_number": "+20-12-1234-1234", "template_id": template.id}
|
||||
@@ -762,7 +761,7 @@ def test_post_sms_notification_returns_400_if_number_not_in_guest_list(
|
||||
notify_db_session, client, restricted
|
||||
):
|
||||
service = create_service(
|
||||
restricted=restricted, service_permissions=[SMS_TYPE, INTERNATIONAL_SMS_TYPE]
|
||||
restricted=restricted, service_permissions=[ServicePermissionType.SMS, ServicePermissionType.INTERNATIONAL_SMS]
|
||||
)
|
||||
template = create_template(service=service)
|
||||
create_api_key(service=service, key_type="team")
|
||||
@@ -860,7 +859,7 @@ def test_post_notification_raises_bad_request_if_not_valid_notification_type(
|
||||
def test_post_notification_with_wrong_type_of_sender(
|
||||
client, sample_template, sample_email_template, notification_type, fake_uuid
|
||||
):
|
||||
if notification_type == EMAIL_TYPE:
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
template = sample_email_template
|
||||
form_label = "sms_sender_id"
|
||||
data = {
|
||||
@@ -868,7 +867,7 @@ def test_post_notification_with_wrong_type_of_sender(
|
||||
"template_id": str(sample_email_template.id),
|
||||
form_label: fake_uuid,
|
||||
}
|
||||
elif notification_type == SMS_TYPE:
|
||||
elif notification_type == ServicePermissionType.SMS:
|
||||
template = sample_template
|
||||
form_label = "email_reply_to_id"
|
||||
data = {
|
||||
@@ -997,7 +996,7 @@ def test_post_email_notification_with_archived_reply_to_id_returns_400(
|
||||
def test_post_notification_with_document_upload(
|
||||
client, notify_db_session, mocker, csv_param
|
||||
):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE])
|
||||
service = create_service(service_permissions=[ServicePermissionType.EMAIL])
|
||||
service.contact_link = "contact.me@gov.uk"
|
||||
template = create_template(
|
||||
service=service,
|
||||
@@ -1055,7 +1054,7 @@ def test_post_notification_with_document_upload(
|
||||
def test_post_notification_with_document_upload_simulated(
|
||||
client, notify_db_session, mocker
|
||||
):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE])
|
||||
service = create_service(service_permissions=[ServicePermissionType.EMAIL])
|
||||
service.contact_link = "contact.me@gov.uk"
|
||||
template = create_template(
|
||||
service=service, template_type="email", content="Document: ((document))"
|
||||
@@ -1092,7 +1091,7 @@ def test_post_notification_with_document_upload_simulated(
|
||||
def test_post_notification_without_document_upload_permission(
|
||||
client, notify_db_session, mocker
|
||||
):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE])
|
||||
service = create_service(service_permissions=[ServicePermissionType.EMAIL])
|
||||
template = create_template(
|
||||
service=service, template_type="email", content="Document: ((document))"
|
||||
)
|
||||
@@ -1234,7 +1233,7 @@ def test_post_notifications_saves_email_or_sms_to_queue(
|
||||
}
|
||||
data.update(
|
||||
{"email_address": "joe.citizen@example.com"}
|
||||
) if notification_type == EMAIL_TYPE else data.update(
|
||||
) if notification_type == NotificationType.EMAIL else data.update(
|
||||
{"phone_number": "+447700900855"}
|
||||
)
|
||||
|
||||
@@ -1297,7 +1296,7 @@ def test_post_notifications_saves_email_or_sms_normally_if_saving_to_queue_fails
|
||||
}
|
||||
data.update(
|
||||
{"email_address": "joe.citizen@example.com"}
|
||||
) if notification_type == EMAIL_TYPE else data.update(
|
||||
) if notification_type == NotificationType.EMAIL else data.update(
|
||||
{"phone_number": "+447700900855"}
|
||||
)
|
||||
|
||||
@@ -1353,7 +1352,7 @@ def test_post_notifications_doesnt_use_save_queue_for_test_notifications(
|
||||
}
|
||||
data.update(
|
||||
{"email_address": "joe.citizen@example.com"}
|
||||
) if notification_type == EMAIL_TYPE else data.update(
|
||||
) if notification_type == NotificationType.EMAIL else data.update(
|
||||
{"phone_number": "+447700900855"}
|
||||
)
|
||||
response = client.post(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from flask import json
|
||||
|
||||
from app.models import EMAIL_TYPE, SMS_TYPE, TEMPLATE_TYPES
|
||||
from app.models import TemplateType
|
||||
from app.utils import DATETIME_FORMAT
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import create_template
|
||||
@@ -12,8 +12,8 @@ valid_version_params = [None, 1]
|
||||
@pytest.mark.parametrize(
|
||||
"tmp_type, expected_name, expected_subject",
|
||||
[
|
||||
(SMS_TYPE, "sms Template Name", None),
|
||||
(EMAIL_TYPE, "email Template Name", "Template subject"),
|
||||
(TemplateType.SMS, "sms Template Name", None),
|
||||
(TemplateType.EMAIL, "email Template Name", "Template subject"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("version", valid_version_params)
|
||||
@@ -56,7 +56,7 @@ def test_get_template_by_id_returns_200(
|
||||
[
|
||||
(
|
||||
{
|
||||
"template_type": SMS_TYPE,
|
||||
"template_type": TemplateType.SMS,
|
||||
"content": "Hello ((placeholder)) ((conditional??yes))",
|
||||
},
|
||||
{
|
||||
@@ -66,7 +66,7 @@ def test_get_template_by_id_returns_200(
|
||||
),
|
||||
(
|
||||
{
|
||||
"template_type": EMAIL_TYPE,
|
||||
"template_type": TemplateType.EMAIL,
|
||||
"subject": "((subject))",
|
||||
"content": "((content))",
|
||||
},
|
||||
@@ -120,7 +120,7 @@ def test_get_template_with_non_existent_template_id_returns_404(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("tmp_type", list(TemplateType))
|
||||
def test_get_template_with_non_existent_version_returns_404(
|
||||
client, sample_service, tmp_type
|
||||
):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from flask import json
|
||||
|
||||
from app.models import EMAIL_TYPE, TEMPLATE_TYPES
|
||||
from app.models import TemplateType
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import create_template
|
||||
|
||||
@@ -59,7 +59,7 @@ valid_post = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("tmp_type", list(TemplateType))
|
||||
@pytest.mark.parametrize(
|
||||
"subject,content,post_data,expected_subject,expected_content,expected_html",
|
||||
valid_post,
|
||||
@@ -93,7 +93,7 @@ def test_valid_post_template_returns_200(
|
||||
|
||||
assert resp_json["id"] == str(template.id)
|
||||
|
||||
if tmp_type == EMAIL_TYPE:
|
||||
if tmp_type == TemplateType.EMAIL:
|
||||
assert expected_subject in resp_json["subject"]
|
||||
assert resp_json["html"] == expected_html
|
||||
else:
|
||||
@@ -105,7 +105,7 @@ def test_valid_post_template_returns_200(
|
||||
def test_email_templates_not_rendered_into_content(client, sample_service):
|
||||
template = create_template(
|
||||
sample_service,
|
||||
template_type=EMAIL_TYPE,
|
||||
template_type=TemplateType.EMAIL,
|
||||
subject="Test",
|
||||
content=("Hello\n" "\r\n" "\r\n" "\n" "# This is a heading\n" "\n" "Paragraph"),
|
||||
)
|
||||
@@ -125,7 +125,7 @@ def test_email_templates_not_rendered_into_content(client, sample_service):
|
||||
assert resp_json["body"] == template.content
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("tmp_type", list(TemplateType))
|
||||
def test_invalid_post_template_returns_400(client, sample_service, tmp_type):
|
||||
template = create_template(
|
||||
sample_service,
|
||||
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
from flask import json
|
||||
from jsonschema.exceptions import ValidationError
|
||||
|
||||
from app.models import EMAIL_TYPE, SMS_TYPE, TEMPLATE_TYPES
|
||||
from app.models import TemplateType
|
||||
from app.schema_validation import validate
|
||||
from app.v2.template.template_schemas import (
|
||||
get_template_by_id_request,
|
||||
@@ -15,7 +15,7 @@ from app.v2.template.template_schemas import (
|
||||
|
||||
valid_json_get_response = {
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-01-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -26,7 +26,7 @@ valid_json_get_response = {
|
||||
|
||||
valid_json_get_response_with_optionals = {
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": EMAIL_TYPE,
|
||||
"type": TemplateType.EMAIL,
|
||||
"created_at": "2017-01-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -114,7 +114,7 @@ def test_get_template_request_schema_against_invalid_args_is_invalid(
|
||||
assert error["message"] in error_message
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("template_type", list(TemplateType))
|
||||
@pytest.mark.parametrize(
|
||||
"response", [valid_json_get_response, valid_json_get_response_with_optionals]
|
||||
)
|
||||
@@ -149,7 +149,7 @@ def test_post_template_preview_against_invalid_args_is_invalid(args, error_messa
|
||||
assert error["message"] in error_messages
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("template_type", list(TemplateType))
|
||||
@pytest.mark.parametrize(
|
||||
"response", [valid_json_post_response, valid_json_post_response_with_optionals]
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ from itertools import product
|
||||
import pytest
|
||||
from flask import json
|
||||
|
||||
from app.models import EMAIL_TYPE, TEMPLATE_TYPES
|
||||
from app.models import TemplateType
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import create_template
|
||||
|
||||
@@ -13,10 +13,10 @@ def test_get_all_templates_returns_200(client, sample_service):
|
||||
create_template(
|
||||
sample_service,
|
||||
template_type=tmp_type,
|
||||
subject="subject_{}".format(name) if tmp_type == EMAIL_TYPE else "",
|
||||
subject="subject_{}".format(name) if tmp_type == TemplateType.EMAIL else "",
|
||||
template_name=name,
|
||||
)
|
||||
for name, tmp_type in product(("A", "B", "C"), TEMPLATE_TYPES)
|
||||
for name, tmp_type in product(("A", "B", "C"), TemplateType)
|
||||
]
|
||||
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
@@ -37,18 +37,18 @@ def test_get_all_templates_returns_200(client, sample_service):
|
||||
assert template["id"] == str(templates[index].id)
|
||||
assert template["body"] == templates[index].content
|
||||
assert template["type"] == templates[index].template_type
|
||||
if templates[index].template_type == EMAIL_TYPE:
|
||||
if templates[index].template_type == TemplateType.EMAIL:
|
||||
assert template["subject"] == templates[index].subject
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("tmp_type", list(TemplateType))
|
||||
def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tmp_type):
|
||||
templates = [
|
||||
create_template(
|
||||
sample_service,
|
||||
template_type=tmp_type,
|
||||
template_name="Template {}".format(i),
|
||||
subject="subject_{}".format(i) if tmp_type == EMAIL_TYPE else "",
|
||||
subject="subject_{}".format(i) if tmp_type == TemplateType.EMAIL else "",
|
||||
)
|
||||
for i in range(3)
|
||||
]
|
||||
@@ -71,11 +71,11 @@ def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tm
|
||||
assert template["id"] == str(templates[index].id)
|
||||
assert template["body"] == templates[index].content
|
||||
assert template["type"] == tmp_type
|
||||
if templates[index].template_type == EMAIL_TYPE:
|
||||
if templates[index].template_type == TemplateType.EMAIL:
|
||||
assert template["subject"] == templates[index].subject
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("tmp_type", list(TemplateType))
|
||||
def test_get_correct_num_templates_for_valid_type_returns_200(
|
||||
client, sample_service, tmp_type
|
||||
):
|
||||
@@ -85,7 +85,7 @@ def test_get_correct_num_templates_for_valid_type_returns_200(
|
||||
for _ in range(num_templates):
|
||||
templates.append(create_template(sample_service, template_type=tmp_type))
|
||||
|
||||
for other_type in TEMPLATE_TYPES:
|
||||
for other_type in TemplateType:
|
||||
if other_type != tmp_type:
|
||||
templates.append(create_template(sample_service, template_type=other_type))
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
from flask import json
|
||||
from jsonschema.exceptions import ValidationError
|
||||
|
||||
from app.models import EMAIL_TYPE, SMS_TYPE, TEMPLATE_TYPES
|
||||
from app.models import TemplateType
|
||||
from app.schema_validation import validate
|
||||
from app.v2.templates.templates_schemas import (
|
||||
get_all_template_request,
|
||||
@@ -16,7 +16,7 @@ valid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-01-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -26,7 +26,7 @@ valid_json_get_all_response = [
|
||||
},
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": EMAIL_TYPE,
|
||||
"type": TemplateType.EMAIL,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 2,
|
||||
@@ -41,7 +41,7 @@ valid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 2,
|
||||
@@ -60,7 +60,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": "invalid_id",
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -77,7 +77,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": "invalid_version",
|
||||
@@ -94,7 +94,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "invalid_created_at",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -111,7 +111,7 @@ invalid_json_get_all_response = [
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -128,7 +128,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -160,7 +160,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
@@ -176,7 +176,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
@@ -192,7 +192,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"created_by": "someone@test.com",
|
||||
@@ -208,7 +208,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -224,7 +224,7 @@ invalid_json_get_all_response = [
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
@@ -239,7 +239,7 @@ invalid_json_get_all_response = [
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"type": SMS_TYPE,
|
||||
"type": TemplateType.SMS,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"created_by": "someone@test.com",
|
||||
@@ -256,19 +256,19 @@ invalid_json_get_all_response = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("template_type", list(TemplateType))
|
||||
def test_get_all_template_request_schema_against_no_args_is_valid(template_type):
|
||||
data = {}
|
||||
assert validate(data, get_all_template_request) == data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("template_type", list(TemplateType))
|
||||
def test_get_all_template_request_schema_against_valid_args_is_valid(template_type):
|
||||
data = {"type": template_type}
|
||||
assert validate(data, get_all_template_request) == data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
@pytest.mark.parametrize("template_type", list(TemplateType))
|
||||
def test_get_all_template_request_schema_against_invalid_args_is_invalid(template_type):
|
||||
data = {"type": "unknown"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user