Return placeholders when getting a template

> Currently when retrieving a template via one of the clients, we do
> not return the personalisation fields that are required for that
> template.
>
> This is useful for services who want to perform template validation on
> their own systems. A service user has also requested this.

– https://www.pivotaltracker.com/story/show/150674476

This commit adds an extra attribute to the JSON response containing an
array of the placeholder names. This key is called "personalisation",
to match the argument that developers use to pass in the values of
placeholders.
This commit is contained in:
Chris Hill-Scott
2017-09-20 10:27:18 +01:00
parent 8360b9a122
commit fa8e4b29f2
3 changed files with 79 additions and 2 deletions

View File

@@ -40,11 +40,57 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
'body': template.content,
"subject": expected_subject,
'name': expected_name,
'personalisation': [],
}
assert json_response == expected_response
@pytest.mark.parametrize("create_template_args, expected_personalisation", [
(
{
"template_type": SMS_TYPE,
"content": "Hello ((placeholder)) ((conditional??yes))",
},
["placeholder", "conditional"]
),
(
{
"template_type": EMAIL_TYPE,
"subject": "((subject))",
"content": "((content))",
},
["subject", "content"]
),
(
{
"template_type": LETTER_TYPE,
"subject": "((letterSubject))",
"content": "((letter_content))",
},
["letterSubject", "letter_content", "contact block"]
)
])
@pytest.mark.parametrize("version", valid_version_params)
def test_get_template_by_id_returns_placeholders(
client,
sample_service_custom_letter_contact_block,
version,
create_template_args,
expected_personalisation,
):
template = create_template(sample_service_custom_letter_contact_block, **create_template_args)
auth_header = create_authorization_header(service_id=sample_service_custom_letter_contact_block.id)
version_path = '/version/{}'.format(version) if version else ''
response = client.get(path='/v2/template/{}{}'.format(template.id, version_path),
headers=[('Content-Type', 'application/json'), auth_header])
json_response = json.loads(response.get_data(as_text=True))
assert json_response['personalisation'] == expected_personalisation
def test_get_template_with_non_existent_template_id_returns_404(client, fake_uuid, sample_service):
auth_header = create_authorization_header(service_id=sample_service.id)