From 382d1de8577cd5f67109b58926f341b6ac2deb0f Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 29 Apr 2019 16:30:31 +0100 Subject: [PATCH] Only count_as_live services Add comments to live services dao test for context --- app/dao/services_dao.py | 4 ++++ tests/app/dao/test_services_dao.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index da71bf595..c4f3f5222 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -87,6 +87,7 @@ def dao_fetch_live_services_data(): Service.name.label("service_name"), Service.consent_to_research, Service.go_live_user_id, + Service.count_as_live, User.name.label('user_name'), User.email_address, User.mobile_number, @@ -109,11 +110,14 @@ def dao_fetch_live_services_data(): this_year_ft_billing, Service.id == this_year_ft_billing.c.service_id ).outerjoin( User, Service.go_live_user_id == User.id + ).filter( + Service.count_as_live == True # noqa ).group_by( Service.id, Organisation.name, Service.name, Service.consent_to_research, + Service.count_as_live, Service.go_live_user_id, User.name, User.email_address, diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 4b559a30d..cc22d82c9 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -391,15 +391,21 @@ def test_dao_fetch_live_services_data(sample_user, mock): template = create_template(service=service) service_2 = create_service(service_name='second', go_live_user=sample_user) create_service(service_name='third') + create_service(service_name='not_live', count_as_live=False) template2 = create_template(service=service, template_type='email') template_letter_1 = create_template(service=service, template_type='letter') template_letter_2 = create_template(service=service_2, template_type='letter') dao_add_service_to_organisation(service=service, organisation_id=org.id) + # two sms billing records for 1st service within current financial year: create_ft_billing(bst_date='2019-04-20', notification_type='sms', template=template, service=service) create_ft_billing(bst_date='2019-04-21', notification_type='sms', template=template, service=service) + # one sms billing record for 1st service from previous financial year, should not appear in the result: create_ft_billing(bst_date='2018-04-20', notification_type='sms', template=template, service=service) + # one email billing record for 1st service within current financial year: create_ft_billing(bst_date='2019-04-20', notification_type='email', template=template2, service=service) + # one letter billing record for 1st service within current financial year: create_ft_billing(bst_date='2019-04-15', notification_type='letter', template=template_letter_1, service=service) + # one letter billing record for 2nd service within current financial year: create_ft_billing(bst_date='2019-04-16', notification_type='letter', template=template_letter_2, service=service_2) results = dao_fetch_live_services_data()