From a6a42d6f263f90b89568f74e8cf19c9bc73511a5 Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Thu, 14 Apr 2016 14:08:35 +0100 Subject: [PATCH] Fixed bug for subject not updating when changed on the edit template page. --- app/main/views/templates.py | 8 +++-- tests/app/main/views/test_templates.py | 44 ++++++++++++++++++++++++-- tests/conftest.py | 4 +-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 135b4c1bf..eda6f572b 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -80,8 +80,12 @@ def edit_service_template(service_id, template_id): if form.validate_on_submit(): service_api_client.update_service_template( - template_id, form.name.data, template['template_type'], - form.template_content.data, service_id + template_id, + form.name.data, + template['template_type'], + form.template_content.data, + service_id, + form.subject.data if getattr(form, 'subject', None) else None ) return redirect(url_for( '.choose_template', diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 7fdf1397a..5f36d6b24 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -52,7 +52,7 @@ def test_should_redirect_when_saving_a_template(app_, 'id': template_id, 'name': name, 'template_content': content, - 'type': 'sms', + 'template_type': 'sms', 'service': service_id } response = client.post(url_for( @@ -64,7 +64,47 @@ def test_should_redirect_when_saving_a_template(app_, assert response.location == url_for( '.choose_template', service_id=service_id, template_type='sms', _external=True) mock_update_service_template.assert_called_with( - template_id, name, 'sms', content, service_id) + template_id, name, 'sms', content, service_id, None) + + +def test_should_redirect_when_saving_a_template_email(app_, + api_user_active, + mock_login, + mock_get_service_email_template, + mock_update_service_template, + mock_get_user, + mock_get_service, + mock_get_user_by_email, + mock_has_permissions, + fake_uuid): + with app_.test_request_context(): + with app_.test_client() as client: + client.login(api_user_active) + service_id = fake_uuid + template_id = fake_uuid + name = "new name" + content = "template content" + subject = "subject" + data = { + 'id': template_id, + 'name': name, + 'template_content': content, + 'template_type': 'email', + 'service': service_id, + 'subject': subject + } + response = client.post(url_for( + '.edit_service_template', + service_id=service_id, + template_id=template_id), data=data) + assert response.status_code == 302 + assert response.location == url_for( + '.choose_template', + service_id=service_id, + template_type='email', + _external=True) + mock_update_service_template.assert_called_with( + template_id, name, 'email', content, service_id, subject) def test_should_show_delete_template_page(app_, diff --git a/tests/conftest.py b/tests/conftest.py index 63811e76d..4b8bb2858 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -205,9 +205,9 @@ def mock_create_service_template(mocker, fake_uuid): @pytest.fixture(scope='function') def mock_update_service_template(mocker): - def _update(id_, name, type_, content, service): + def _update(id_, name, type_, content, service, subject=None): template = template_json( - service, id_, name, type_, content) + service, id_, name, type_, content, subject) return {'data': template} return mocker.patch(