From 5ebae9c66ccb1c06a35064d41c98cb38fe405a1f Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Mon, 23 May 2016 14:00:28 +0100 Subject: [PATCH] only return unarchived templates when getting all templates get_specific_template functions happily return archived templates --- app/dao/templates_dao.py | 3 ++- tests/app/dao/test_templates_dao.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/dao/templates_dao.py b/app/dao/templates_dao.py index dbd822672..eba2212f1 100644 --- a/app/dao/templates_dao.py +++ b/app/dao/templates_dao.py @@ -42,7 +42,8 @@ def dao_get_template_by_id(template_id, version=None): def dao_get_all_templates_for_service(service_id): return Template.query.filter_by( - service=Service.query.get(service_id) + service_id=service_id, + archived=False ).order_by( asc(Template.updated_at), asc(Template.created_at) ).all() diff --git a/tests/app/dao/test_templates_dao.py b/tests/app/dao/test_templates_dao.py index 8327ea3e4..445fbbba0 100644 --- a/tests/app/dao/test_templates_dao.py +++ b/tests/app/dao/test_templates_dao.py @@ -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 +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): sample_template = create_sample_template( notify_db,