mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-02 23:47:42 -04:00
Use Zendesk form for branding requests
This changes the Zendesk tickets created when an email or letter branding request is submitted to use the new Zendesk Form that was introduced in https://github.com/alphagov/notifications-utils/pull/899
This commit is contained in:
@@ -1207,8 +1207,8 @@ def branding_request(service_id, branding_type):
|
||||
elif branding_type == "letter":
|
||||
branding_name = current_service.letter_branding_name
|
||||
if form.validate_on_submit():
|
||||
zendesk_client.create_ticket(
|
||||
subject='{} branding request - {}'.format(branding_type.capitalize(), current_service.name),
|
||||
ticket = NotifySupportTicket(
|
||||
subject=f'{branding_type.capitalize()} branding request - {current_service.name}',
|
||||
message=(
|
||||
'Organisation: {organisation}\n'
|
||||
'Service: {service_name}\n'
|
||||
@@ -1228,11 +1228,14 @@ def branding_request(service_id, branding_type):
|
||||
new_paragraph='\n\n' if form.something_else.data else '',
|
||||
detail=form.something_else.data or ''
|
||||
),
|
||||
ticket_type=zendesk_client.TYPE_QUESTION,
|
||||
user_email=current_user.email_address,
|
||||
ticket_type=NotifySupportTicket.TYPE_QUESTION,
|
||||
user_name=current_user.name,
|
||||
tags=['notify_action', 'notify_branding'],
|
||||
user_email=current_user.email_address,
|
||||
org_id=current_service.organisation_id,
|
||||
org_type=current_service.organisation_type,
|
||||
service_id=current_service.id
|
||||
)
|
||||
zendesk_client.send_ticket_to_zendesk(ticket)
|
||||
flash((
|
||||
'Thanks for your branding request. We’ll get back to you '
|
||||
'within one working day.'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import re
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
from unittest.mock import Mock, PropertyMock, call
|
||||
from unittest.mock import ANY, Mock, PropertyMock, call
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
@@ -10,6 +10,9 @@ from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.clients.zendesk.zendesk_client import (
|
||||
NotifySupportTicket,
|
||||
)
|
||||
|
||||
import app
|
||||
from app.formatters import email_safe
|
||||
@@ -5063,18 +5066,21 @@ def test_submit_email_branding_request(
|
||||
expected_organisation,
|
||||
):
|
||||
service_one['email_branding'] = sample_uuid()
|
||||
organisation_id = ORGANISATION_ID if org_name else None
|
||||
|
||||
mocker.patch(
|
||||
'app.models.service.Service.organisation_id',
|
||||
new_callable=PropertyMock,
|
||||
return_value=ORGANISATION_ID if org_name else None,
|
||||
return_value=organisation_id,
|
||||
)
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_json(name=org_name),
|
||||
)
|
||||
|
||||
zendesk = mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.create_ticket',
|
||||
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
|
||||
mock_send_ticket_to_zendesk = mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk',
|
||||
autospec=True,
|
||||
)
|
||||
|
||||
@@ -5084,7 +5090,8 @@ def test_submit_email_branding_request(
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
zendesk.assert_called_once_with(
|
||||
mock_create_ticket.assert_called_once_with(
|
||||
ANY,
|
||||
message='\n'.join([
|
||||
'Organisation: {}',
|
||||
'Service: service one',
|
||||
@@ -5096,10 +5103,13 @@ def test_submit_email_branding_request(
|
||||
]).format(expected_organisation, requested_branding),
|
||||
subject='Email branding request - service one',
|
||||
ticket_type='question',
|
||||
user_email='test@user.gov.uk',
|
||||
user_name='Test User',
|
||||
tags=['notify_action', 'notify_branding'],
|
||||
user_email='test@user.gov.uk',
|
||||
org_id=organisation_id,
|
||||
org_type='central',
|
||||
service_id=SERVICE_ONE_ID
|
||||
)
|
||||
mock_send_ticket_to_zendesk.assert_called_once()
|
||||
assert normalize_spaces(page.select_one('.banner-default').text) == (
|
||||
'Thanks for your branding request. We’ll get back to you '
|
||||
'within one working day.'
|
||||
@@ -5146,19 +5156,21 @@ def test_submit_letter_branding_request(
|
||||
expected_organisation,
|
||||
):
|
||||
service_one['letter_branding'] = sample_uuid()
|
||||
organisation_id = ORGANISATION_ID if org_name else None
|
||||
|
||||
mocker.patch(
|
||||
'app.models.service.Service.organisation_id',
|
||||
new_callable=PropertyMock,
|
||||
return_value=ORGANISATION_ID if org_name else None,
|
||||
return_value=organisation_id,
|
||||
)
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_json(name=org_name),
|
||||
)
|
||||
|
||||
zendesk = mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.create_ticket',
|
||||
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
|
||||
mock_send_ticket_to_zendesk = mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk',
|
||||
autospec=True,
|
||||
)
|
||||
|
||||
@@ -5168,7 +5180,8 @@ def test_submit_letter_branding_request(
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
zendesk.assert_called_once_with(
|
||||
mock_create_ticket.assert_called_once_with(
|
||||
ANY,
|
||||
message='\n'.join([
|
||||
'Organisation: {}',
|
||||
'Service: service one',
|
||||
@@ -5180,10 +5193,13 @@ def test_submit_letter_branding_request(
|
||||
]).format(expected_organisation, requested_branding),
|
||||
subject='Letter branding request - service one',
|
||||
ticket_type='question',
|
||||
user_email='test@user.gov.uk',
|
||||
user_name='Test User',
|
||||
tags=['notify_action', 'notify_branding'],
|
||||
user_email='test@user.gov.uk',
|
||||
org_id=organisation_id,
|
||||
org_type='central',
|
||||
service_id=SERVICE_ONE_ID
|
||||
)
|
||||
mock_send_ticket_to_zendesk.assert_called_once()
|
||||
assert normalize_spaces(page.select_one('.banner-default').text) == (
|
||||
'Thanks for your branding request. We’ll get back to you '
|
||||
'within one working day.'
|
||||
@@ -5208,7 +5224,7 @@ def test_submit_letter_branding_request_redirects_if_from_template_is_set(
|
||||
branding_type,
|
||||
|
||||
):
|
||||
mocker.patch('app.main.views.service_settings.zendesk_client.create_ticket', autospec=True)
|
||||
mocker.patch('app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk', autospec=True)
|
||||
data = {'options': 'something_else', 'something_else': 'Homer Simpson'}
|
||||
|
||||
if from_template:
|
||||
@@ -5240,8 +5256,9 @@ def test_submit_branding_when_something_else_is_only_option(
|
||||
branding_type,
|
||||
current_branding,
|
||||
):
|
||||
zendesk = mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.create_ticket',
|
||||
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
|
||||
mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk',
|
||||
autospec=True,
|
||||
)
|
||||
|
||||
@@ -5258,7 +5275,7 @@ def test_submit_branding_when_something_else_is_only_option(
|
||||
'Branding requested: Something else\n'
|
||||
'\n'
|
||||
'Homer Simpson'.format(current_branding)
|
||||
) in zendesk.call_args_list[0][1]['message']
|
||||
) in mock_create_ticket.call_args_list[0][1]['message']
|
||||
|
||||
|
||||
def test_service_settings_links_to_branding_request_page_for_letters(
|
||||
|
||||
Reference in New Issue
Block a user