From f91c0a820f0c55b40cae892cc44288ac32cfeac1 Mon Sep 17 00:00:00 2001 From: Richard Chapman Date: Tue, 21 Nov 2017 10:53:29 +0000 Subject: [PATCH] Fixed bug in test which was passing but not testing the services_dao correctly The dao_fetch_monthly_historical_usage_by_template_for_service code wasn't being tested properly due to an bug on the test which created a notification with the same template and hence was not testing that a specific service would have a different template id. - Fixed the bug in the test - Update services_dao so that the service id check is made --- app/dao/services_dao.py | 1 + tests/app/dao/test_services_dao.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index cafca04fd..58772b0b4 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -576,6 +576,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year) Template, Notification.template_id == Template.id, ).filter( Notification.created_at >= start_date, + Notification.service_id == service_id ).group_by( Notification.template_id, Template.name, diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 926e5ea57..f172769e7 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -1496,6 +1496,13 @@ def test_dao_fetch_monthly_historical_usage_by_template_for_service_only_returns notification_history(created_at=datetime(year, 2, day)) service_two = create_service(service_name='other_service') + template_two = create_sample_template( + notify_db, + notify_db_session, + template_name='1', + template_type='email', + service=service_two + ) daily_stats_template_usage_by_month() @@ -1503,7 +1510,7 @@ def test_dao_fetch_monthly_historical_usage_by_template_for_service_only_returns notify_db, notify_db_session, service=sample_service, - template=template_one, + template=template_two, created_at=datetime.utcnow() )