From de65c30624fa420b1ce77a6d734c8f321a6f5a03 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 19 Sep 2018 17:34:26 +0100 Subject: [PATCH] Tag request to go live tickets automatically MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment we manually tag tickets as they come in so we can analyse how many of each type we’re getting. Further, we manually tag all the request to go live tickets once a month to analyse how many are complete/incomplete. All this tagging is useful, but quite time consuming. Notify already knows this information and – using the Zendesk API – we can tag them automatically. I’ve checked with Holly and this is the taxonomy we want to use. --- app/main/views/service_settings.py | 48 ++++++++++- tests/app/main/views/test_service_settings.py | 81 ++++++++++++++++++- 2 files changed, 123 insertions(+), 6 deletions(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 46d9a7319..0b9fc0702 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -222,7 +222,7 @@ def submit_request_to_go_live(service_id): service_dashboard=url_for('main.service_dashboard', service_id=current_service.id, _external=True), organisation_type=str(current_service.organisation_type).title(), agreement=AgreementInfo.from_current_user().as_human_readable, - checklist='Yes' if current_service.go_live_checklist_completed else 'No', + checklist=current_service.go_live_checklist_completed_as_yes_no, volume_email=form.volume_email.data, volume_sms=form.volume_sms.data, volume_letter=form.volume_letter.data, @@ -235,7 +235,8 @@ 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 + user_name=current_user.name, + tags=get_request_to_go_live_tags(current_service, current_user), ) flash('Thanks for your request to go live. We’ll get back to you within one working day.', 'default') @@ -1106,3 +1107,46 @@ def check_contact_details_type(contact_details): return 'email_address' else: return 'phone_number' + + +def get_request_to_go_live_tags(service, user): + return list(_get_request_to_go_live_tags( + service, + AgreementInfo.from_user(user).agreement_signed, + )) + + +def _get_request_to_go_live_tags(service, agreement_signed): + + BASE = 'notify_request_to_go_live' + COMPLETE = BASE + '_complete' + INCOMPLETE = BASE + '_incomplete' + + yield BASE + + if service.go_live_checklist_completed and agreement_signed: + return COMPLETE + + yield INCOMPLETE + + if not service.go_live_checklist_completed: + yield INCOMPLETE + '_checklist' + + if not agreement_signed: + yield INCOMPLETE + '_mou' + + if service.has_email_templates and not service.has_email_reply_to_address: + yield INCOMPLETE + '_email_reply_to' + + if not service.has_team_members: + yield INCOMPLETE + '_team_member' + + if not service.has_templates: + yield INCOMPLETE + '_template_content' + + if ( + service.has_sms_templates and + service.shouldnt_use_govuk_as_sms_sender and + service.sms_sender_is_govuk + ): + yield INCOMPLETE + '_sms_sender' diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index c3f48ea51..5be558213 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -758,7 +758,14 @@ def test_should_redirect_after_request_to_go_live( message=ANY, ticket_type=ZendeskClient.TYPE_QUESTION, user_name=active_user_with_permissions.name, - user_email=active_user_with_permissions.email_address + user_email=active_user_with_permissions.email_address, + tags=[ + 'notify_request_to_go_live', + 'notify_request_to_go_live_incomplete', + 'notify_request_to_go_live_incomplete_checklist', + 'notify_request_to_go_live_incomplete_mou', + 'notify_request_to_go_live_incomplete_team_member', + ], ) assert mock_post.call_args[1]['message'] == ( 'Service: service one\n' @@ -794,7 +801,9 @@ def test_should_redirect_after_request_to_go_live( 'has_email_reply_to_address,' 'shouldnt_use_govuk_as_sms_sender,' 'sms_sender_is_govuk,' - 'expected,' + 'expected_readyness,' + 'agreement_signed,' + 'expected_tags,' ), ( ( # Just sending email @@ -806,6 +815,10 @@ def test_should_redirect_after_request_to_go_live( True, True, 'Yes', + True, + [ + 'notify_request_to_go_live', + ], ), ( # Needs to set reply to address True, @@ -816,6 +829,13 @@ def test_should_redirect_after_request_to_go_live( True, True, 'No', + True, + [ + 'notify_request_to_go_live', + 'notify_request_to_go_live_incomplete', + 'notify_request_to_go_live_incomplete_checklist', + 'notify_request_to_go_live_incomplete_email_reply_to', + ], ), ( # Just sending SMS True, @@ -826,6 +846,10 @@ def test_should_redirect_after_request_to_go_live( True, False, 'Yes', + True, + [ + 'notify_request_to_go_live', + ], ), ( # Needs to change SMS sender True, @@ -836,6 +860,13 @@ def test_should_redirect_after_request_to_go_live( True, True, 'No', + True, + [ + 'notify_request_to_go_live', + 'notify_request_to_go_live_incomplete', + 'notify_request_to_go_live_incomplete_checklist', + 'notify_request_to_go_live_incomplete_sms_sender', + ], ), ( # Needs team members False, @@ -846,6 +877,13 @@ def test_should_redirect_after_request_to_go_live( True, False, 'No', + True, + [ + 'notify_request_to_go_live', + 'notify_request_to_go_live_incomplete', + 'notify_request_to_go_live_incomplete_checklist', + 'notify_request_to_go_live_incomplete_team_member', + ], ), ( # Needs templates True, @@ -856,6 +894,34 @@ def test_should_redirect_after_request_to_go_live( True, False, 'No', + True, + [ + 'notify_request_to_go_live', + 'notify_request_to_go_live_incomplete', + 'notify_request_to_go_live_incomplete_checklist', + 'notify_request_to_go_live_incomplete_template_content', + ], + ), + ( # Everything is wrong + False, + False, + True, + True, + False, + True, + True, + 'No', + False, + [ + 'notify_request_to_go_live', + 'notify_request_to_go_live_incomplete', + 'notify_request_to_go_live_incomplete_checklist', + 'notify_request_to_go_live_incomplete_mou', + 'notify_request_to_go_live_incomplete_email_reply_to', + 'notify_request_to_go_live_incomplete_team_member', + 'notify_request_to_go_live_incomplete_template_content', + 'notify_request_to_go_live_incomplete_sms_sender', + ], ), ), ) @@ -869,7 +935,9 @@ def test_ready_to_go_live( has_email_reply_to_address, shouldnt_use_govuk_as_sms_sender, sms_sender_is_govuk, - expected, + expected_readyness, + agreement_signed, + expected_tags, ): for prop in { 'has_team_members', @@ -887,7 +955,12 @@ def test_ready_to_go_live( assert app.notify_client.models.Service({ 'id': fake_uuid() - }).go_live_checklist_completed_as_yes_no == expected + }).go_live_checklist_completed_as_yes_no == expected_readyness + + assert list(app.main.views.service_settings._get_request_to_go_live_tags( + app.notify_client.models.Service({'id': fake_uuid()}), + agreement_signed, + )) == expected_tags @pytest.mark.parametrize('route', [