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.
This commit is contained in:
Chris Hill-Scott
2019-04-04 11:27:05 +01:00
parent 3565ffc33f
commit 9684e962ae
3 changed files with 31 additions and 32 deletions

View File

@@ -244,7 +244,7 @@ def submit_request_to_go_live(service_id):
ticket_type=zendesk_client.TYPE_QUESTION, ticket_type=zendesk_client.TYPE_QUESTION,
user_email=current_user.email_address, user_email=current_user.email_address,
user_name=current_user.name, 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. Well get back to you within one working day.', 'default') flash('Thanks for your request to go live. Well get back to you within one working day.', 'default')
@@ -1072,34 +1072,6 @@ def check_contact_details_type(contact_details):
return 'phone_number' 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): def print_if_number(value):
return value if isinstance(value, int) else '' return value if isinstance(value, int) else ''

View File

@@ -543,3 +543,30 @@ class Service(JSONModel):
def get_api_key(self, id): def get_api_key(self, id):
return self._get_by_id(self.api_keys, 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

View File

@@ -1555,9 +1555,9 @@ def test_ready_to_go_live(
'id': SERVICE_ONE_ID 'id': SERVICE_ONE_ID
}).go_live_checklist_completed_as_yes_no == expected_readyness }).go_live_checklist_completed_as_yes_no == expected_readyness
assert list(app.main.views.service_settings._get_request_to_go_live_tags( assert app.models.service.Service(
app.models.service.Service({'id': SERVICE_ONE_ID}) {'id': SERVICE_ONE_ID}
)) == expected_tags ).request_to_go_live_tags == expected_tags
@pytest.mark.parametrize('route', [ @pytest.mark.parametrize('route', [