mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Add JSON schema for updating template
We did not have a JSON schema for updating a template. Since we will remove the postage constraint from the templates table, this adds a JSON schema for updating a template so that we can use it to check that the postage is one of the allowed values.
This commit is contained in:
@@ -37,7 +37,7 @@ from app.models import SMS_TYPE, Template, SECOND_CLASS, LETTER_TYPE
|
||||
from app.notifications.validators import service_has_permission, check_reply_to
|
||||
from app.schema_validation import validate
|
||||
from app.schemas import (template_schema, template_history_schema)
|
||||
from app.template.template_schemas import post_create_template_schema
|
||||
from app.template.template_schemas import post_create_template_schema, post_update_template_schema
|
||||
from app.utils import get_public_notify_type_text
|
||||
|
||||
template_blueprint = Blueprint('template', __name__, url_prefix='/service/<uuid:service_id>/template')
|
||||
@@ -110,6 +110,7 @@ def update_template(service_id, template_id):
|
||||
raise InvalidRequest(errors, 403)
|
||||
|
||||
data = request.get_json()
|
||||
validate(data, post_update_template_schema)
|
||||
|
||||
# if redacting, don't update anything else
|
||||
if data.get('redact_personalisation') is True:
|
||||
|
||||
@@ -2,7 +2,7 @@ from app.models import (
|
||||
TEMPLATE_PROCESS_TYPE,
|
||||
TEMPLATE_TYPES,
|
||||
)
|
||||
from app.schema_validation.definitions import uuid
|
||||
from app.schema_validation.definitions import nullable_uuid, uuid
|
||||
|
||||
post_create_template_schema = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
@@ -13,7 +13,7 @@ post_create_template_schema = {
|
||||
"name": {"type": "string"},
|
||||
"template_type": {"enum": TEMPLATE_TYPES},
|
||||
"service": uuid,
|
||||
"process_type": {"emun": TEMPLATE_PROCESS_TYPE},
|
||||
"process_type": {"enum": TEMPLATE_PROCESS_TYPE},
|
||||
"content": {"type": "string"},
|
||||
"subject": {"type": "string"},
|
||||
"created_by": uuid,
|
||||
@@ -28,3 +28,24 @@ post_create_template_schema = {
|
||||
"then": {"required": ["subject"]},
|
||||
"required": ["name", "template_type", "content", "service", "created_by"]
|
||||
}
|
||||
|
||||
post_update_template_schema = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST update existing template",
|
||||
"type": "object",
|
||||
"title": "payload for POST /service/<uuid:service_id>/template/<uuid:template_id>",
|
||||
"properties": {
|
||||
"id": uuid,
|
||||
"name": {"type": "string"},
|
||||
"template_type": {"enum": TEMPLATE_TYPES},
|
||||
"service": uuid,
|
||||
"process_type": {"enum": TEMPLATE_PROCESS_TYPE},
|
||||
"content": {"type": "string"},
|
||||
"subject": {"type": "string"},
|
||||
"postage": {"type": "string", "format": "postage"},
|
||||
"reply_to": nullable_uuid,
|
||||
"created_by": uuid,
|
||||
"archived": {"type": "boolean"},
|
||||
"current_user": uuid
|
||||
},
|
||||
}
|
||||
|
||||
@@ -884,6 +884,19 @@ def test_update_template_reply_to_set_to_blank(client, notify_db_session):
|
||||
assert th.service_letter_contact_id is None
|
||||
|
||||
|
||||
def test_update_template_validates_postage(admin_request, sample_service_full_permissions):
|
||||
template = create_template(service=sample_service_full_permissions, template_type='letter')
|
||||
|
||||
response = admin_request.post(
|
||||
'template.update_template',
|
||||
service_id=sample_service_full_permissions.id,
|
||||
template_id=template.id,
|
||||
_data={"postage": "third"},
|
||||
_expected_status=400
|
||||
)
|
||||
assert 'postage invalid' in response['errors'][0]['message']
|
||||
|
||||
|
||||
def test_update_template_with_foreign_service_reply_to(client, sample_letter_template):
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user