diff --git a/app/v2/template/template_schemas.py b/app/v2/template/template_schemas.py index 0a326ecdd..6f08d9cfc 100644 --- a/app/v2/template/template_schemas.py +++ b/app/v2/template/template_schemas.py @@ -1,6 +1,5 @@ from app.models import SMS_TYPE, TEMPLATE_TYPES from app.schema_validation.definitions import uuid, personalisation -from app.v2.template_schema import template get_template_by_id_request = { @@ -68,51 +67,6 @@ post_template_preview_response = { "required": ["id", "type", "version", "body"] } -get_all_template_request = { - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "request schema for parameters allowed when getting all templates", - "type": "object", - "properties": { - "type": {"enum": TEMPLATE_TYPES}, - }, - "required": ["type"], - "additionalProperties": False, -} - -get_all_template_response = { - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "GET response schema when getting all templates", - "type": "object", - "properties": { - "links": { - "type": "object", - "properties": { - "self": { - "type": "string", - "format": "uri" - }, - "next": { - "type": "string", - "format": "uri" - } - }, - "additionalProperties": False, - "required": ["self"], - }, - "templates": { - "type": "array", - "items": { - "type": "object", - "$ref": "#/definitions/template" - } - } - }, - "required": ["links", "templates"], - "definitions": { - "template": template - } -} - def create_post_template_preview_response(template, template_object): subject = template_object.subject if template.template_type != SMS_TYPE else None diff --git a/app/v2/template_schema.py b/app/v2/template_schema.py deleted file mode 100644 index 24252f083..000000000 --- a/app/v2/template_schema.py +++ /dev/null @@ -1,15 +0,0 @@ -from app.schema_validation.definitions import uuid - -# this may belong in a templates module -template = { - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "template schema", - "type": "object", - "title": "notification content", - "properties": { - "id": uuid, - "version": {"type": "integer"}, - "uri": {"type": "string", "format": "uri"} - }, - "required": ["id", "version", "uri"] -} diff --git a/app/v2/templates/get_templates.py b/app/v2/templates/get_templates.py index a5f4e6f0c..348ed13cc 100644 --- a/app/v2/templates/get_templates.py +++ b/app/v2/templates/get_templates.py @@ -14,6 +14,8 @@ def get_templates(): templates = templates_dao.dao_get_all_templates_for_service(api_user.service_id) + print(templates) + return jsonify( templates=[template.serialize() for template in templates] ), 200 diff --git a/app/v2/templates/templates_schemas.py b/app/v2/templates/templates_schemas.py index 0520b70c2..d5b335874 100644 --- a/app/v2/templates/templates_schemas.py +++ b/app/v2/templates/templates_schemas.py @@ -1,5 +1,5 @@ from app.models import TEMPLATE_TYPES -from app.v2.template_schema import template +from app.v2.template.template_schemas import get_template_by_id_response as template get_all_template_request = { diff --git a/tests/app/v2/templates/test_templates_schemas.py b/tests/app/v2/templates/test_templates_schemas.py index f60f4366b..d42233513 100644 --- a/tests/app/v2/templates/test_templates_schemas.py +++ b/tests/app/v2/templates/test_templates_schemas.py @@ -15,12 +15,38 @@ from jsonschema.exceptions import ValidationError valid_json_get_all_response = [ { "templates": [ - {"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"}, - {"id": str(uuid.uuid4()), "version": 2, "uri": "http://template/id"} + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-01-10T18:25:43.511Z', + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + }, + { + 'id': str(uuid.uuid4()), + 'type': EMAIL_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 2, + 'created_by': 'someone@test.com', + 'body': 'some body' + } ] }, { - "templates": [{"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"}] + "templates": [ + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 2, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] }, { "templates": [] @@ -30,32 +56,139 @@ valid_json_get_all_response = [ invalid_json_get_all_response = [ ({ "templates": [ - {"id": 'invalid_id', "version": 1, "uri": "http://template/id"} + { + 'id': 'invalid_id', + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + } ] }, ['templates is not a valid UUID']), ({ "templates": [ - {"id": str(uuid.uuid4()), "version": 'invalid_version', "uri": "http://template/id"} + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 'invalid_version', + 'created_by': 'someone@test.com', + 'body': 'some body' + } ] }, ['templates invalid_version is not of type integer']), ({ "templates": [ - {"id": str(uuid.uuid4()), "version": 1, "uri": "invalid_uri"} + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': 'invalid_created_at', + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + } ] - }, ['templates invalid_uri is not a valid URI.']), + }, ['templates invalid_created_at is not a date-time']), ({}, ['templates is a required property']), ({ - "templates": [{"version": 1, "uri": "http://template/id"}] + "templates": [ + { + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] }, ['templates id is a required property']), ({ - "templates": [{"id": str(uuid.uuid4()), "uri": "http://template/id"}] + "templates": [ + { + 'id': str(uuid.uuid4()), + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] + }, ['templates type is a required property']), + ({ + "templates": [ + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] + }, ['templates created_at is a required property']), + ({ + "templates": [ + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'version': 1, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] + }, ['templates updated_at is a required property']), + ({ + "templates": [ + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] }, ['templates version is a required property']), ({ - "templates": [{"id": str(uuid.uuid4()), "version": 1}] - }, ['templates uri is a required property']), + "templates": [ + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 1, + 'body': 'some body' + } + ] + }, ['templates created_by is a required property']), ({ - "templates": [{"version": 1}] - }, ['templates id is a required property', 'templates uri is a required property']), + "templates": [ + { + 'id': str(uuid.uuid4()), + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'version': 1, + 'created_by': 'someone@test.com' + } + ] + }, ['templates body is a required property']), + ({ + "templates": [ + { + 'type': SMS_TYPE, + 'created_at': '2017-02-10T18:25:43.511Z', + 'updated_at': None, + 'created_by': 'someone@test.com', + 'body': 'some body' + } + ] + }, ['templates id is a required property', 'templates version is a required property']), ]