mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Don't return hidden templates in API service template responses
Brings back filtering hidden templates from the API responses.
This commit is contained in:
@@ -216,6 +216,7 @@ def sample_template(
|
||||
template_type="sms",
|
||||
content="This is a template:\nwith a newline",
|
||||
archived=False,
|
||||
hidden=False,
|
||||
subject_line='Subject',
|
||||
user=None,
|
||||
service=None,
|
||||
@@ -237,6 +238,7 @@ def sample_template(
|
||||
'service': service,
|
||||
'created_by': created_by,
|
||||
'archived': archived,
|
||||
'hidden': hidden,
|
||||
'process_type': process_type
|
||||
}
|
||||
if template_type in ['email', 'letter']:
|
||||
|
||||
@@ -286,6 +286,29 @@ def test_get_all_templates_ignores_archived_templates(notify_db, notify_db_sessi
|
||||
assert templates[0] == normal_template
|
||||
|
||||
|
||||
def test_get_all_templates_ignores_hidden_templates(notify_db, notify_db_session, sample_service):
|
||||
normal_template = create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Normal Template',
|
||||
service=sample_service,
|
||||
archived=False
|
||||
)
|
||||
|
||||
create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Hidden Template',
|
||||
hidden=True,
|
||||
service=sample_service
|
||||
)
|
||||
|
||||
templates = dao_get_all_templates_for_service(sample_service.id)
|
||||
|
||||
assert len(templates) == 1
|
||||
assert templates[0] == normal_template
|
||||
|
||||
|
||||
def test_get_template_by_id_and_service(notify_db, notify_db_session, sample_service):
|
||||
sample_template = create_sample_template(
|
||||
notify_db,
|
||||
@@ -301,6 +324,39 @@ def test_get_template_by_id_and_service(notify_db, notify_db_session, sample_ser
|
||||
assert not template.redact_personalisation
|
||||
|
||||
|
||||
def test_get_template_by_id_and_service_returns_none_for_hidden_templates(notify_db, notify_db_session, sample_service):
|
||||
sample_template = create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Test Template',
|
||||
hidden=True,
|
||||
service=sample_service
|
||||
)
|
||||
|
||||
with pytest.raises(NoResultFound):
|
||||
dao_get_template_by_id_and_service_id(
|
||||
template_id=sample_template.id,
|
||||
service_id=sample_service.id
|
||||
)
|
||||
|
||||
|
||||
def test_get_template_version_returns_none_for_hidden_templates(notify_db, notify_db_session, sample_service):
|
||||
sample_template = create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Test Template',
|
||||
hidden=True,
|
||||
service=sample_service
|
||||
)
|
||||
|
||||
with pytest.raises(NoResultFound):
|
||||
dao_get_template_by_id_and_service_id(
|
||||
sample_template.id,
|
||||
sample_service.id,
|
||||
'1'
|
||||
)
|
||||
|
||||
|
||||
def test_get_template_by_id_and_service_returns_none_if_no_template(sample_service, fake_uuid):
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
dao_get_template_by_id_and_service_id(template_id=fake_uuid, service_id=sample_service.id)
|
||||
@@ -408,6 +464,18 @@ def test_get_template_versions(sample_template):
|
||||
assert len(v) == 2
|
||||
|
||||
|
||||
def test_get_template_versions_is_empty_for_hidden_templates(notify_db, notify_db_session, sample_service):
|
||||
sample_template = create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Test Template',
|
||||
hidden=True,
|
||||
service=sample_service
|
||||
)
|
||||
versions = dao_get_template_versions(service_id=sample_template.service_id, template_id=sample_template.id)
|
||||
assert len(versions) == 0
|
||||
|
||||
|
||||
def test_get_templates_by_ids_successful(notify_db, notify_db_session):
|
||||
template_1 = create_sample_template(
|
||||
notify_db,
|
||||
|
||||
Reference in New Issue
Block a user