only return unarchived templates when getting all templates

get_specific_template functions happily return archived templates
This commit is contained in:
Leo Hemsted
2016-05-23 14:00:28 +01:00
parent a436ff32a1
commit 5ebae9c66c
2 changed files with 26 additions and 1 deletions

View File

@@ -42,7 +42,8 @@ def dao_get_template_by_id(template_id, version=None):
def dao_get_all_templates_for_service(service_id): def dao_get_all_templates_for_service(service_id):
return Template.query.filter_by( return Template.query.filter_by(
service=Service.query.get(service_id) service_id=service_id,
archived=False
).order_by( ).order_by(
asc(Template.updated_at), asc(Template.created_at) asc(Template.updated_at), asc(Template.created_at)
).all() ).all()

View File

@@ -140,6 +140,30 @@ def test_get_all_returns_empty_list_if_no_templates(sample_service):
assert len(dao_get_all_templates_for_service(sample_service.id)) == 0 assert len(dao_get_all_templates_for_service(sample_service.id)) == 0
def test_get_all_templates_ignores_archived_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
)
archived_template = create_sample_template(
notify_db,
notify_db_session,
template_name='Archived Template',
service=sample_service
)
# sample_template fixture uses dao, which forces archived = False at creation.
archived_template.archived = True
dao_update_template(archived_template)
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): def test_get_template_by_id_and_service(notify_db, notify_db_session, sample_service):
sample_template = create_sample_template( sample_template = create_sample_template(
notify_db, notify_db,