Fixed bug for subject not updating when changed on the edit template page.

This commit is contained in:
Nicholas Staples
2016-04-14 14:08:35 +01:00
parent b157da24cb
commit a6a42d6f26
3 changed files with 50 additions and 6 deletions

View File

@@ -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',

View File

@@ -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_,

View File

@@ -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(