From 41b49eb8e0d232bfba345dc1c55674dc26786241 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 17 Jan 2017 15:48:51 +0000 Subject: [PATCH] Make the update template endpoint work when process_type is present. --- app/schemas.py | 1 + app/template/rest.py | 2 +- tests/app/template/test_rest.py | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/schemas.py b/app/schemas.py index a7fe2ff11..a33a6d47c 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -208,6 +208,7 @@ class BaseTemplateSchema(BaseSchema): class TemplateSchema(BaseTemplateSchema): created_by = field_for(models.Template, 'created_by', required=True) + process_type = field_for(models.Template, 'process_type') @validates_schema def validate_type(self, data): diff --git a/app/template/rest.py b/app/template/rest.py index 0f3fabbed..cfa1643e2 100644 --- a/app/template/rest.py +++ b/app/template/rest.py @@ -144,5 +144,5 @@ def _strip_html(content): def _template_has_not_changed(current_data, updated_template): return all( current_data[key] == updated_template[key] - for key in ('name', 'content', 'subject', 'archived') + for key in ('name', 'content', 'subject', 'archived', 'process_type') ) diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index fbd8c83ad..8f6e01ba3 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -1,4 +1,3 @@ -import pytest import json import random import string @@ -42,11 +41,17 @@ def test_should_create_a_new_template_for_a_service( assert json_resp['data']['service'] == str(sample_service.id) assert json_resp['data']['id'] assert json_resp['data']['version'] == 1 + assert json_resp['data']['process_type'] == 'normal' + assert json_resp['data']['created_by'] == str(sample_user.id) if subject: assert json_resp['data']['subject'] == 'subject' else: assert not json_resp['data']['subject'] + template = Template.query.get(json_resp['data']['id']) + from app.schemas import template_schema + assert sorted(json_resp['data']) == sorted(template_schema.dump(template).data) + def test_should_be_error_if_service_does_not_exist_on_create(client, sample_user, fake_uuid): data = { @@ -335,6 +340,7 @@ def test_should_get_a_single_template( assert response.status_code == 200 assert data['content'] == content assert data['subject'] == subject + assert data['process_type'] == 'normal' @pytest.mark.parametrize( @@ -516,3 +522,17 @@ def test_update_does_not_create_new_version_when_there_is_no_change(client, samp template = dao_get_template_by_id(sample_template.id) assert template.version == 1 + + +def test_update_set_process_type_on_template(client, sample_template): + auth_header = create_authorization_header() + data = { + 'process_type': 'priority' + } + resp = client.post('/service/{}/template/{}'.format(sample_template.service_id, sample_template.id), + data=json.dumps(data), + headers=[('Content-Type', 'application/json'), auth_header]) + assert resp.status_code == 200 + + template = dao_get_template_by_id(sample_template.id) + assert template.process_type == 'priority'