From d675ceb5c21b88edc7a21034cf2256a8a8f82faa Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 24 Apr 2018 17:37:15 +0100 Subject: [PATCH] send zendesk rather than deskpro tickets --- app/__init__.py | 6 +- app/config.py | 10 +--- app/main/views/feedback.py | 10 ++-- app/main/views/service_settings.py | 8 +-- manifest-base.yml | 3 +- manifest-prototype-2-base.yml | 3 +- manifest-prototype-base.yml | 3 +- pytest.ini | 3 +- requirements.txt | 2 +- tests/app/main/views/test_feedback.py | 57 +++++++++---------- tests/app/main/views/test_service_settings.py | 2 +- 11 files changed, 48 insertions(+), 59 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 7cf17d9a9..47a055169 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -25,7 +25,7 @@ from functools import partial from notifications_python_client.errors import HTTPError from notifications_utils import logging, request_helper, formatters -from notifications_utils.clients import DeskproClient +from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient from notifications_utils.clients.statsd.statsd_client import StatsdClient from notifications_utils.recipients import ( validate_phone_number, @@ -78,7 +78,7 @@ organisations_client = OrganisationsClient() org_invite_api_client = OrgInviteApiClient() asset_fingerprinter = AssetFingerprinter() statsd_client = StatsdClient() -deskpro_client = DeskproClient() +zendesk_client = ZendeskClient() letter_jobs_client = LetterJobsClient() inbound_number_client = InboundNumberClient() billing_api_client = BillingAPIClient() @@ -99,7 +99,7 @@ def create_app(application): init_app(application) statsd_client.init_app(application) - deskpro_client.init_app(application) + zendesk_client.init_app(application) logging.init_app(application, statsd_client) csrf.init_app(application) request_helper.init_app(application) diff --git a/app/config.py b/app/config.py index e8985ab01..016be2aa1 100644 --- a/app/config.py +++ b/app/config.py @@ -12,8 +12,7 @@ class Config(object): API_HOST_NAME = os.environ.get('API_HOST_NAME') SECRET_KEY = os.environ.get('SECRET_KEY') DANGEROUS_SALT = os.environ.get('DANGEROUS_SALT') - DESKPRO_API_HOST = os.environ.get('DESKPRO_API_HOST') - DESKPRO_API_KEY = os.environ.get('DESKPRO_API_KEY') + ZENDESK_API_KEY = os.environ.get('ZENDESK_API_KEY') # if we're not on cloudfoundry, we can get to this app from localhost. but on cloudfoundry its different ADMIN_BASE_URL = os.environ.get('ADMIN_BASE_URL', 'http://localhost:6012') @@ -28,9 +27,6 @@ class Config(object): DEBUG = False NOTIFY_LOG_PATH = os.getenv('NOTIFY_LOG_PATH') - DESKPRO_DEPT_ID = 5 - DESKPRO_ASSIGNED_AGENT_TEAM_ID = 5 - ADMIN_CLIENT_USER_NAME = 'notify-admin' ASSETS_DEBUG = False AWS_REGION = 'eu-west-1' @@ -60,7 +56,6 @@ class Config(object): WTF_CSRF_ENABLED = True WTF_CSRF_TIME_LIMIT = None CSV_UPLOAD_BUCKET_NAME = 'local-notifications-csv-upload' - DESKPRO_PERSON_EMAIL = 'donotreply@notifications.service.gov.uk' ACTIVITY_STATS_LIMIT_DAYS = 7 TEST_MESSAGE_FILENAME = 'Report' @@ -92,8 +87,7 @@ class Development(Config): API_HOST_NAME = 'http://localhost:6011' DANGEROUS_SALT = 'dev-notify-salt' SECRET_KEY = 'dev-notify-secret-key' - DESKPRO_API_HOST = "some-host" - DESKPRO_API_KEY = "some-key" + ZENDESK_API_KEY = "some-key" class Test(Development): diff --git a/app/main/views/feedback.py b/app/main/views/feedback.py index fec897efa..e7d31328d 100644 --- a/app/main/views/feedback.py +++ b/app/main/views/feedback.py @@ -3,13 +3,13 @@ from datetime import datetime import pytz from flask import abort, redirect, render_template, request, session, url_for from flask_login import current_user -from notifications_utils.clients import DeskproError +from notifications_utils.clients.zendesk.zendesk_client import ZendeskError from app import ( convert_to_boolean, current_service, - deskpro_client, service_api_client, + zendesk_client, ) from app.main import main from app.main.forms import Feedback, Problem, SupportType, Triage @@ -137,15 +137,15 @@ def feedback(ticket_type): ) try: - deskpro_client.create_ticket( + zendesk_client.create_ticket( subject='Notify feedback {}'.format(user_name), message=feedback_msg, ticket_type=ticket_type, - urgency=10 if urgent else 1, + p1=urgent, user_email=user_email, user_name=user_name ) - except DeskproError: + except ZendeskError: abort(500, "Feedback submission failed") return redirect(url_for('.thanks', urgent=urgent, anonymous=anonymous)) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 259869743..551226c28 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -10,19 +10,19 @@ from flask import ( ) from flask_login import current_user, login_required from notifications_python_client.errors import HTTPError -from notifications_utils.clients import DeskproError +from notifications_utils.clients.zendesk.zendesk_client import ZendeskError from notifications_utils.field import Field from notifications_utils.formatters import formatted_list from app import ( billing_api_client, current_service, - deskpro_client, email_branding_client, inbound_number_client, organisations_client, service_api_client, user_api_client, + zendesk_client, ) from app.main import main from app.main.forms import ( @@ -191,7 +191,7 @@ def submit_request_to_go_live(service_id): if form.validate_on_submit(): try: - deskpro_client.create_ticket( + zendesk_client.create_ticket( subject='Request to go live - {}'.format(current_service['name']), message=( 'On behalf of {} ({})\n' @@ -223,7 +223,7 @@ def submit_request_to_go_live(service_id): user_email=current_user.email_address, user_name=current_user.name ) - except DeskproError: + except ZendeskError: abort(500, "Request to go live submission failed") flash('Thanks for your request to go live. We’ll get back to you within one working day.', 'default') diff --git a/manifest-base.yml b/manifest-base.yml index d1c00b2df..61a04c0be 100644 --- a/manifest-base.yml +++ b/manifest-base.yml @@ -30,8 +30,7 @@ env: STATSD_PREFIX: null - DESKPRO_API_HOST: null - DESKPRO_API_KEY: null + ZENDESK_API_KEY: null TEMPLATE_PREVIEW_API_HOST: null TEMPLATE_PREVIEW_API_KEY: null diff --git a/manifest-prototype-2-base.yml b/manifest-prototype-2-base.yml index e7927749e..284fb6427 100644 --- a/manifest-prototype-2-base.yml +++ b/manifest-prototype-2-base.yml @@ -21,8 +21,7 @@ env: STATSD_PREFIX: null - DESKPRO_API_HOST: null - DESKPRO_API_KEY: null + ZENDESK_API_KEY: null TEMPLATE_PREVIEW_API_HOST: null TEMPLATE_PREVIEW_API_KEY: null diff --git a/manifest-prototype-base.yml b/manifest-prototype-base.yml index 6003594b7..d2165800e 100644 --- a/manifest-prototype-base.yml +++ b/manifest-prototype-base.yml @@ -21,8 +21,7 @@ env: STATSD_PREFIX: null - DESKPRO_API_HOST: null - DESKPRO_API_KEY: null + ZENDESK_API_KEY: null TEMPLATE_PREVIEW_API_HOST: null TEMPLATE_PREVIEW_API_KEY: null diff --git a/pytest.ini b/pytest.ini index b603dc4a4..8ab99e048 100644 --- a/pytest.ini +++ b/pytest.ini @@ -6,7 +6,6 @@ env = API_HOST_NAME=test DANGEROUS_SALT=dev-notify-salt SECRET_KEY=dev-notify-secret-key - DESKPRO_API_HOST=test - DESKPRO_API_KEY=test + ZENDESK_API_KEY=test STATSD_PREFIX=stats-prefix REDIS_ENABLED=0 diff --git a/requirements.txt b/requirements.txt index 1c9ca61f2..d04071d7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,4 +18,4 @@ notifications-python-client==4.8.1 # PaaS awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@26.2.0#egg=notifications-utils==26.2.0 +git+https://github.com/alphagov/notifications-utils.git@27.0.0#egg=notifications-utils==27.0.0 diff --git a/tests/app/main/views/test_feedback.py b/tests/app/main/views/test_feedback.py index 5e0740b80..94f1020ef 100644 --- a/tests/app/main/views/test_feedback.py +++ b/tests/app/main/views/test_feedback.py @@ -5,13 +5,7 @@ import pytest from bs4 import BeautifulSoup, element from flask import url_for from freezegun import freeze_time -from notifications_utils.clients import DeskproError -from tests.conftest import ( - active_user_with_permissions, - mock_get_services, - mock_get_services_with_no_services, - mock_get_services_with_one_service, -) +from notifications_utils.clients.zendesk.zendesk_client import ZendeskError from werkzeug.exceptions import InternalServerError from app.main.views.feedback import ( @@ -20,6 +14,12 @@ from app.main.views.feedback import ( has_live_services, in_business_hours, ) +from tests.conftest import ( + active_user_with_permissions, + mock_get_services, + mock_get_services_with_no_services, + mock_get_services_with_one_service, +) def no_redirect(): @@ -118,7 +118,7 @@ def test_get_feedback_page_with_prefilled_body( user = active_user_with_permissions(fake_uuid) user.email_address = 'test@marinemanagement.org.uk' mocker.patch('app.user_api_client.get_user', return_value=user) - mock_post = mocker.patch('app.main.views.feedback.deskpro_client.create_ticket') + mock_post = mocker.patch('app.main.views.feedback.zendesk_client.create_ticket') page = client_request.get( 'main.feedback', ticket_type=QUESTION_TICKET_TYPE, @@ -141,7 +141,7 @@ def test_get_feedback_page_with_prefilled_body( @freeze_time('2016-12-12 12:00:00.000000') @pytest.mark.parametrize('ticket_type', [PROBLEM_TICKET_TYPE, QUESTION_TICKET_TYPE]) def test_passed_non_logged_in_user_details_through_flow(client, mocker, ticket_type): - mock_post = mocker.patch('app.main.views.feedback.deskpro_client.create_ticket') + mock_post = mocker.patch('app.main.views.feedback.zendesk_client.create_ticket') data = {'feedback': 'blah', 'name': 'Steve Irwin', 'email_address': 'rip@gmail.com'} @@ -158,7 +158,7 @@ def test_passed_non_logged_in_user_details_through_flow(client, mocker, ticket_t user_email='rip@gmail.com', user_name='Steve Irwin', ticket_type=ticket_type, - urgency=ANY, + p1=ANY ) @@ -174,7 +174,7 @@ def test_passes_user_details_through_flow( ticket_type, data ): - mock_post = mocker.patch('app.main.views.feedback.deskpro_client.create_ticket') + mock_post = mocker.patch('app.main.views.feedback.zendesk_client.create_ticket') resp = logged_in_client.post( url_for('main.feedback', ticket_type=ticket_type), @@ -189,7 +189,7 @@ def test_passes_user_details_through_flow( user_email='test@user.gov.uk', user_name='Test User', ticket_type=ticket_type, - urgency=ANY, + p1=ANY ) assert mock_post.call_args[1]['message'] == '\n'.join([ 'Environment: http://localhost/', @@ -221,7 +221,7 @@ def test_email_address_required_for_problems( things_expected_in_url, expected_error ): - mocker.patch('app.main.views.feedback.deskpro_client') + mocker.patch('app.main.views.feedback.zendesk_client') response = client.post( url_for('main.feedback', ticket_type=ticket_type), data=data, @@ -234,21 +234,21 @@ def test_email_address_required_for_problems( assert isinstance(page.find('span', {'class': 'error-message'}), expected_error) -@pytest.mark.parametrize('ticket_type, severe, is_in_business_hours, numeric_urgency, is_urgent', [ +@pytest.mark.parametrize('ticket_type, severe, is_in_business_hours, is_p1', [ # business hours, always urgent - (PROBLEM_TICKET_TYPE, 'yes', True, 10, True), - (QUESTION_TICKET_TYPE, 'yes', True, 10, True), - (PROBLEM_TICKET_TYPE, 'no', True, 10, True), - (QUESTION_TICKET_TYPE, 'no', True, 10, True), + (PROBLEM_TICKET_TYPE, 'yes', True, True), + (QUESTION_TICKET_TYPE, 'yes', True, True), + (PROBLEM_TICKET_TYPE, 'no', True, True), + (QUESTION_TICKET_TYPE, 'no', True, True), # out of hours, non emergency, never urgent - (PROBLEM_TICKET_TYPE, 'no', False, 1, False), - (QUESTION_TICKET_TYPE, 'no', False, 1, False), + (PROBLEM_TICKET_TYPE, 'no', False, False), + (QUESTION_TICKET_TYPE, 'no', False, False), # out of hours, emergency problems are urgent - (PROBLEM_TICKET_TYPE, 'yes', False, 10, True), - (QUESTION_TICKET_TYPE, 'yes', False, 1, False), + (PROBLEM_TICKET_TYPE, 'yes', False, True), + (QUESTION_TICKET_TYPE, 'yes', False, False), ]) def test_urgency( @@ -257,18 +257,17 @@ def test_urgency( ticket_type, severe, is_in_business_hours, - numeric_urgency, - is_urgent, + is_p1, ): mocker.patch('app.main.views.feedback.in_business_hours', return_value=is_in_business_hours) - mock_post = mocker.patch('app.main.views.feedback.deskpro_client.create_ticket') + mock_post = mocker.patch('app.main.views.feedback.zendesk_client.create_ticket') response = logged_in_client.post( url_for('main.feedback', ticket_type=ticket_type, severe=severe), data={'feedback': 'blah', 'email_address': 'test@example.com'}, ) assert response.status_code == 302 - assert response.location == url_for('main.thanks', urgent=is_urgent, anonymous=False, _external=True) - assert mock_post.call_args[1]['urgency'] == numeric_urgency + assert response.location == url_for('main.thanks', urgent=is_p1, anonymous=False, _external=True) + assert mock_post.call_args[1]['p1'] == is_p1 ids, params = zip(*[ @@ -506,8 +505,8 @@ def test_bat_email_page( @pytest.mark.parametrize('ticket_type', [PROBLEM_TICKET_TYPE, QUESTION_TICKET_TYPE]) def test_log_error_on_post(app_, mocker, ticket_type): mock_post = mocker.patch( - 'app.main.views.feedback.deskpro_client.create_ticket', - side_effect=DeskproError + 'app.main.views.feedback.zendesk_client.create_ticket', + side_effect=ZendeskError(None) ) with app_.test_request_context(): with app_.test_client() as client: diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 7a2c81eb2..bde31d976 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -561,7 +561,7 @@ def test_should_redirect_after_request_to_go_live( single_sms_sender, mock_get_service_settings_page_common ): - mock_post = mocker.patch('app.main.views.service_settings.deskpro_client.create_ticket') + mock_post = mocker.patch('app.main.views.service_settings.zendesk_client.create_ticket') page = client_request.post( 'main.submit_request_to_go_live', service_id=SERVICE_ONE_ID,