Add endpoint for getting / creating a hidden template

We want a way of getting the hidden precompiled template from admin,
so this adds an endpoint which gets the template or creates it if it doesn't
exist. The function to get or create the hidden template already existed
but has been moved to the template DAO now that it is used in more
places.
This commit is contained in:
Katie Smith
2019-09-05 12:07:35 +01:00
parent 5cdce44e42
commit 0c1fa3852f
4 changed files with 85 additions and 30 deletions

View File

@@ -389,6 +389,50 @@ def test_should_be_able_to_archive_template(client, sample_template):
assert Template.query.first().archived
def test_get_precompiled_template_for_service(
client,
notify_user,
sample_service,
):
assert len(sample_service.templates) == 0
response = client.get(
'/service/{}/template/precompiled'.format(sample_service.id),
headers=[create_authorization_header()],
)
assert response.status_code == 200
assert len(sample_service.templates) == 1
data = json.loads(response.get_data(as_text=True))
assert data['name'] == 'Pre-compiled PDF'
assert data['hidden'] is True
def test_get_precompiled_template_for_service_when_service_has_existing_precompiled_template(
client,
notify_user,
sample_service,
):
create_template(
sample_service,
template_name='Exisiting precompiled template',
template_type=LETTER_TYPE,
hidden=True)
assert len(sample_service.templates) == 1
response = client.get(
'/service/{}/template/precompiled'.format(sample_service.id),
headers=[create_authorization_header()],
)
assert response.status_code == 200
assert len(sample_service.templates) == 1
data = json.loads(response.get_data(as_text=True))
assert data['name'] == 'Exisiting precompiled template'
assert data['hidden'] is True
def test_should_be_able_to_get_all_templates_for_a_service(client, sample_user, sample_service):
data = {
'name': 'my template 1',