From 689ff57c32a9ff6a4beec4c5f05753e2ce38d7e6 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Fri, 3 May 2019 11:00:53 +0100 Subject: [PATCH] Add organisation type to live services report --- app/dao/services_dao.py | 3 +++ tests/app/dao/test_services_dao.py | 8 ++++---- tests/app/db.py | 5 +++-- tests/app/service/test_rest.py | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 0ec8d8492..6e1b6ceed 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -84,6 +84,7 @@ def dao_fetch_live_services_data(): data = db.session.query( Service.id, Organisation.name.label("organisation_name"), + Organisation.organisation_type, Service.name.label("service_name"), Service.consent_to_research, Service.go_live_user_id, @@ -117,6 +118,7 @@ def dao_fetch_live_services_data(): ).group_by( Service.id, Organisation.name, + Organisation.organisation_type, Service.name, Service.consent_to_research, Service.count_as_live, @@ -151,6 +153,7 @@ def dao_fetch_live_services_data(): "service_id": row.id, "service_name": row.service_name, "organisation_name": row.organisation_name, + "organisation_type": row.organisation_type, "consent_to_research": row.consent_to_research, "contact_name": row.user_name, "contact_email": row.email_address, diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index aa6cd11e4..5aae5854e 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -386,7 +386,7 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user( @freeze_time('2019-04-23T10:00:00') def test_dao_fetch_live_services_data(sample_user, mock): - org = create_organisation() + org = create_organisation(organisation_type='crown') service = create_service(go_live_user=sample_user, go_live_at='2014-04-20T10:00:00') template = create_template(service=service) service_2 = create_service(service_name='second', go_live_user=sample_user, go_live_at='2017-04-20T10:00:00') @@ -416,19 +416,19 @@ def test_dao_fetch_live_services_data(sample_user, mock): # checks the results and that they are ordered by date: assert results == [ {'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1', - 'consent_to_research': None, 'contact_name': 'Test User', + 'organisation_type': 'crown', 'consent_to_research': None, 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986', 'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None, 'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1}, {'service_id': mock.ANY, 'service_name': 'third', 'organisation_name': None, 'consent_to_research': None, - 'contact_name': None, 'contact_email': None, + 'organisation_type': None, 'contact_name': None, 'contact_email': None, 'contact_mobile': None, 'live_date': datetime(2016, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None, 'letter_volume_intent': None, 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0}, {'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None, 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None, - 'email_volume_intent': None, 'letter_volume_intent': None, + 'organisation_type': None, 'email_volume_intent': None, 'letter_volume_intent': None, 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1} ] diff --git a/tests/app/db.py b/tests/app/db.py index baf4cad52..e0863f006 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -541,10 +541,11 @@ def create_domain(domain, organisation_id): return domain -def create_organisation(name='test_org_1', active=True): +def create_organisation(name='test_org_1', active=True, organisation_type=None): data = { 'name': name, - 'active': active + 'active': active, + 'organisation_type': organisation_type } organisation = Organisation(**data) dao_create_organisation(organisation) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 4d93585d7..f57d523e2 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -153,12 +153,12 @@ def test_get_live_services_data(sample_user, admin_request, mock): 'contact_mobile': '+447700900986', 'contact_name': 'Test User', 'email_totals': 0, 'email_volume_intent': None, 'letter_totals': 0, 'letter_volume_intent': None, 'live_date': None, 'organisation_name': None, 'service_id': mock.ANY, 'service_name': 'second', 'sms_totals': 0, - 'sms_volume_intent': None} in response + 'sms_volume_intent': None, 'organisation_type': None} in response assert {'consent_to_research': None, 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986', 'contact_name': 'Test User', 'email_totals': 1, 'email_volume_intent': None, 'letter_totals': 0, 'letter_volume_intent': None, 'live_date': None, 'organisation_name': 'test_org_1', 'service_id': mock.ANY, 'service_name': 'Sample service', - 'sms_totals': 1, 'sms_volume_intent': None} in response + 'sms_totals': 1, 'sms_volume_intent': None, 'organisation_type': None} in response def test_get_service_by_id(admin_request, sample_service):