diff --git a/app/v2/templates/templates_schemas.py b/app/v2/templates/templates_schemas.py index 5b1899b67..0520b70c2 100644 --- a/app/v2/templates/templates_schemas.py +++ b/app/v2/templates/templates_schemas.py @@ -1,5 +1,4 @@ from app.models import TEMPLATE_TYPES -from app.schema_validation.definitions import uuid from app.v2.template_schema import template @@ -8,8 +7,7 @@ get_all_template_request = { "description": "request schema for parameters allowed when getting all templates", "type": "object", "properties": { - "type": {"enum": TEMPLATE_TYPES}, - "older_than": uuid + "type": {"enum": TEMPLATE_TYPES} }, "additionalProperties": False, } @@ -19,21 +17,6 @@ get_all_template_response = { "description": "GET response schema when getting all templates", "type": "object", "properties": { - "links": { - "type": "object", - "properties": { - "current": { - "type": "string", - "format": "uri" - }, - "next": { - "type": "string", - "format": "uri" - } - }, - "additionalProperties": False, - "required": ["current"], - }, "templates": { "type": "array", "items": { @@ -42,7 +25,7 @@ get_all_template_response = { } } }, - "required": ["links", "templates"], + "required": ["templates"], "definitions": { "template": template } diff --git a/tests/app/v2/templates/test_templates_schemas.py b/tests/app/v2/templates/test_templates_schemas.py index a629ee65c..f60f4366b 100644 --- a/tests/app/v2/templates/test_templates_schemas.py +++ b/tests/app/v2/templates/test_templates_schemas.py @@ -14,68 +14,46 @@ from jsonschema.exceptions import ValidationError valid_json_get_all_response = [ { - 'links': {'current': 'http://some.path', 'next': 'http://some.other.path'}, "templates": [ {"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"}, {"id": str(uuid.uuid4()), "version": 2, "uri": "http://template/id"} ] }, { - 'links': {'current': 'http://some.path'}, "templates": [{"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"}] }, { - 'links': {'current': 'http://some.path'}, "templates": [] } ] invalid_json_get_all_response = [ ({ - 'links': {'current': 'invalid_uri'}, - "templates": [ - {"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"} - ] - }, ['links invalid_uri is not a valid URI.']), - ({ - 'links': {'current': 'http://some.path'}, "templates": [ {"id": 'invalid_id', "version": 1, "uri": "http://template/id"} ] }, ['templates is not a valid UUID']), ({ - 'links': {'current': 'http://some.path'}, "templates": [ {"id": str(uuid.uuid4()), "version": 'invalid_version', "uri": "http://template/id"} ] }, ['templates invalid_version is not of type integer']), ({ - 'links': {'current': 'http://some.path'}, "templates": [ {"id": str(uuid.uuid4()), "version": 1, "uri": "invalid_uri"} ] }, ['templates invalid_uri is not a valid URI.']), + ({}, ['templates is a required property']), ({ - 'links': {'current': 'http://some.path'} - }, ['templates is a required property']), - ({ - 'links': {'next': 'http://some.other.path'}, - "templates": [{"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"}] - }, ['links current is a required property']), - ({ - 'links': {'current': 'http://some.path', 'next': 'http://some.other.path'}, "templates": [{"version": 1, "uri": "http://template/id"}] }, ['templates id is a required property']), ({ - 'links': {'current': 'http://some.path', 'next': 'http://some.other.path'}, "templates": [{"id": str(uuid.uuid4()), "uri": "http://template/id"}] }, ['templates version is a required property']), ({ - 'links': {'current': 'http://some.path', 'next': 'http://some.other.path'}, "templates": [{"id": str(uuid.uuid4()), "version": 1}] }, ['templates uri is a required property']), ({ - 'links': {'current': 'http://some.path', 'next': 'http://some.other.path'}, "templates": [{"version": 1}] }, ['templates id is a required property', 'templates uri is a required property']), ] @@ -93,12 +71,6 @@ def test_get_all_template_request_schema_against_valid_args_is_valid(template_ty assert validate(data, get_all_template_request) == data -@pytest.mark.parametrize("template_type", TEMPLATE_TYPES) -def test_get_all_template_request_schema_against_valid_args_with_optional_is_valid(template_type, fake_uuid): - data = {'type': template_type, 'older_than': fake_uuid} - assert validate(data, get_all_template_request) == data - - @pytest.mark.parametrize("template_type", TEMPLATE_TYPES) def test_get_all_template_request_schema_against_invalid_args_is_invalid(template_type): data = {'type': 'unknown'} @@ -112,19 +84,6 @@ def test_get_all_template_request_schema_against_invalid_args_is_invalid(templat assert errors['errors'][0]['message'] == 'type unknown is not one of [sms, email, letter]' -@pytest.mark.parametrize("template_type", TEMPLATE_TYPES) -def test_get_all_template_request_schema_against_invalid_args_with_optional_is_invalid(template_type): - data = {'type': template_type, 'older_than': 'invalid_uuid'} - - with pytest.raises(ValidationError) as e: - validate(data, get_all_template_request) - errors = json.loads(str(e.value)) - - assert errors['status_code'] == 400 - assert len(errors['errors']) == 1 - assert errors['errors'][0]['message'] == 'older_than is not a valid UUID' - - @pytest.mark.parametrize("response", valid_json_get_all_response) def test_valid_get_all_templates_response_schema_is_valid(response): assert validate(response, get_all_template_response) == response