From 9684e962ae4850bb4d954beb0db2ee5c8f69eeff Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 4 Apr 2019 11:27:05 +0100 Subject: [PATCH] Refactor go live tags into service model Since this function only takes one argument, a service, it might as well be a method of the service. --- app/main/views/service_settings.py | 30 +------------------ app/models/service.py | 27 +++++++++++++++++ tests/app/main/views/test_service_settings.py | 6 ++-- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 966ca1649..409b9ad2e 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -244,7 +244,7 @@ def submit_request_to_go_live(service_id): ticket_type=zendesk_client.TYPE_QUESTION, user_email=current_user.email_address, user_name=current_user.name, - tags=get_request_to_go_live_tags(current_service), + tags=current_service.request_to_go_live_tags, ) flash('Thanks for your request to go live. We’ll get back to you within one working day.', 'default') @@ -1072,34 +1072,6 @@ def check_contact_details_type(contact_details): return 'phone_number' -def get_request_to_go_live_tags(service): - return list(_get_request_to_go_live_tags(service)) - - -def _get_request_to_go_live_tags(service): - - BASE = 'notify_request_to_go_live' - - yield BASE - - if service.go_live_checklist_completed and service.organisation.agreement_signed: - yield BASE + '_complete' - return - - for test, tag in ( - (True, ''), - (not service.volumes, '_volumes'), - (not service.go_live_checklist_completed, '_checklist'), - (not service.organisation.agreement_signed, '_mou'), - (service.needs_to_add_email_reply_to_address, '_email_reply_to'), - (not service.has_team_members, '_team_member'), - (not service.has_templates, '_template_content'), - (service.needs_to_change_sms_sender, '_sms_sender'), - ): - if test: - yield BASE + '_incomplete' + tag - - def print_if_number(value): return value if isinstance(value, int) else '' diff --git a/app/models/service.py b/app/models/service.py index c28e6ff62..c0b1b5e6b 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -543,3 +543,30 @@ class Service(JSONModel): def get_api_key(self, id): return self._get_by_id(self.api_keys, id) + + @property + def request_to_go_live_tags(self): + return list(self._get_request_to_go_live_tags()) + + def _get_request_to_go_live_tags(self): + + BASE = 'notify_request_to_go_live' + + yield BASE + + if self.go_live_checklist_completed and self.organisation.agreement_signed: + yield BASE + '_complete' + return + + for test, tag in ( + (True, ''), + (not self.volumes, '_volumes'), + (not self.go_live_checklist_completed, '_checklist'), + (not self.organisation.agreement_signed, '_mou'), + (self.needs_to_add_email_reply_to_address, '_email_reply_to'), + (not self.has_team_members, '_team_member'), + (not self.has_templates, '_template_content'), + (self.needs_to_change_sms_sender, '_sms_sender'), + ): + if test: + yield BASE + '_incomplete' + tag diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 6fcabf559..78d25e59c 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1555,9 +1555,9 @@ def test_ready_to_go_live( 'id': SERVICE_ONE_ID }).go_live_checklist_completed_as_yes_no == expected_readyness - assert list(app.main.views.service_settings._get_request_to_go_live_tags( - app.models.service.Service({'id': SERVICE_ONE_ID}) - )) == expected_tags + assert app.models.service.Service( + {'id': SERVICE_ONE_ID} + ).request_to_go_live_tags == expected_tags @pytest.mark.parametrize('route', [