From b6ebbe6f679bf586906f7484a0cfb2ecbf9bf6ea Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Tue, 9 Jul 2019 10:38:07 +0100 Subject: [PATCH] Add organisation_type property to Service model This will return the organisation_type of the service's organisation (if there is one), or the organisation_type of the service if not. --- app/models/service.py | 5 ++++- tests/app/models/test_service.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/service.py b/app/models/service.py index 7b09ca5e5..e9c9de6a5 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -32,7 +32,6 @@ class Service(JSONModel): 'letter_contact_block', 'message_limit', 'name', - 'organisation_type', 'permissions', 'prefix_sms', 'research_mode', @@ -409,6 +408,10 @@ class Service(JSONModel): def organisation_id(self): return self._dict['organisation'] + @property + def organisation_type(self): + return self.organisation.organisation_type or self._dict['organisation_type'] + @cached_property def inbound_number(self): return inbound_number_client.get_inbound_sms_number_for_service(self.id)['data'].get('number', '') diff --git a/tests/app/models/test_service.py b/tests/app/models/test_service.py index d24ed8821..49d84ab07 100644 --- a/tests/app/models/test_service.py +++ b/tests/app/models/test_service.py @@ -2,6 +2,7 @@ import uuid from app.models.service import Service from app.models.user import User +from tests import organisation_json INV_PARENT_FOLDER_ID = '7e979e79-d970-43a5-ac69-b625a8d147b0' INV_CHILD_1_FOLDER_ID = '92ee1ee0-e4ee-4dcc-b1a7-a5da9ebcfa2b' @@ -173,3 +174,20 @@ def test_get_template_folders_shows_all_folders_when_user_id_not_passed_in( 'users_with_permission': [active_user_with_permissions['id']], } ] + + +def test_organisation_type_when_services_organisation_has_no_org_type(mocker, service_one, organisation_one): + service = Service(service_one) + mocker.patch('app.organisations_client.get_service_organisation', return_value=organisation_one) + + assert not organisation_one['organisation_type'] + assert service.organisation_type == 'central' + + +def test_organisation_type_when_service_and_its_org_both_have_an_org_type(mocker, service_one): + # service_one has an organisation_type of 'central' + service = Service(service_one) + org = organisation_json(organisation_type='local') + mocker.patch('app.organisations_client.get_service_organisation', return_value=org) + + assert service.organisation_type == 'local'