diff --git a/app/main/forms.py b/app/main/forms.py index df00bcd9b..d688f98f1 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -2130,6 +2130,7 @@ class BrandingOptions(StripWhitespaceForm): def __init__(self, service, *args, branding_type="email", **kwargs): super().__init__(*args, **kwargs) + self.branding_type = branding_type self.options.choices = tuple(self.get_available_choices(service, branding_type)) self.options.label.text = 'Choose your new {} branding'.format(branding_type) if self.something_else_is_only_option: @@ -2194,16 +2195,24 @@ class BrandingOptions(StripWhitespaceForm): return self.options.choices == (self.FALLBACK_OPTION,) def validate_something_else(self, field): - if ( - self.something_else_is_only_option - or self.options.data == self.FALLBACK_OPTION_VALUE - ) and not field.data: - raise ValidationError('Cannot be empty') + if self.branding_type == 'email': + if self.something_else_is_only_option and not field.data: + raise ValidationError('Cannot be empty') + elif self.branding_type == 'letter': + if ( + self.something_else_is_only_option + or self.options.data == self.FALLBACK_OPTION_VALUE + ) and not field.data: + raise ValidationError('Cannot be empty') if self.options.data != self.FALLBACK_OPTION_VALUE: field.data = '' +class SomethingElseBrandingForm(StripWhitespaceForm): + something_else = TextAreaField('', validators=[DataRequired('Cannot be empty')]) + + class ServiceDataRetentionForm(StripWhitespaceForm): notification_type = GovukRadiosField( diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index f3a044136..0a5d3763b 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -65,6 +65,7 @@ from app.main.forms import ( SetEmailBranding, SetLetterBranding, SMSPrefixForm, + SomethingElseBrandingForm, ) from app.utils import DELIVERED_STATUSES, FAILURE_STATUSES, SENDING_STATUSES from app.utils.user import ( @@ -1130,34 +1131,58 @@ def link_service_to_organisation(service_id): ) +def create_email_branding_zendesk_ticket(form_option_selected, detail=None): + form = BrandingOptions(current_service) + + ticket_message = render_template( + 'support-tickets/branding-request.txt', + current_branding=current_service.email_branding_name, + branding_requested=dict(form.options.choices)[form_option_selected], + detail=detail, + ) + ticket = NotifySupportTicket( + subject=f'Email branding request - {current_service.name}', + message=ticket_message, + ticket_type=NotifySupportTicket.TYPE_QUESTION, + user_name=current_user.name, + 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) + + @main.route("/services//branding-request/email", methods=['GET', 'POST']) @user_has_permissions('manage_service') def email_branding_request(service_id): form = BrandingOptions(current_service, branding_type='email') branding_name = current_service.email_branding_name if form.validate_on_submit(): - ticket_message = render_template( - 'support-tickets/branding-request.txt', - current_branding=branding_name, - branding_requested=dict(form.options.choices)[form.options.data], - detail=form.something_else.data, - ) - ticket = NotifySupportTicket( - subject=f'Email branding request - {current_service.name}', - message=ticket_message, - ticket_type=NotifySupportTicket.TYPE_QUESTION, - user_name=current_user.name, - 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.' - ), 'default') - return redirect(url_for('.service_settings', service_id=current_service.id)) + if form.something_else_is_only_option: + create_email_branding_zendesk_ticket( + form_option_selected=form.options.data, + detail=form.something_else.data, + ) + + flash('Thanks for your branding request. We’ll get back to you within one working day.', 'default') + return redirect(url_for('.service_settings', service_id=current_service.id)) + else: + endpoint = { + 'govuk': '.email_branding_govuk', + 'govuk_and_org': '.email_branding_govuk', + 'nhs': '.email_branding_nhs', + 'organisation': '.email_branding_organisation', + 'something_else': '.email_branding_something_else', + }[form.options.data] + + return redirect( + url_for( + endpoint, + service_id=current_service.id, + with_org=(True if form.options.data == 'govuk_and_org' else None), + ) + ) return render_template( 'views/service-settings/branding/email-branding-options.html', @@ -1166,6 +1191,58 @@ def email_branding_request(service_id): ) +@main.route("/services//service-settings/email-branding/govuk", methods=['GET', 'POST']) +@user_has_permissions('manage_service') +def email_branding_govuk(service_id): + with_org = request.args.get('with_org') + + if request.method == 'POST': + create_email_branding_zendesk_ticket(request.form['branding_choice']) + + flash('Thanks for your branding request. We’ll get back to you within one working day.', 'default') + return redirect(url_for('.service_settings', service_id=current_service.id)) + + return render_template('views/service-settings/branding/email-branding-govuk.html', with_org=with_org) + + +@main.route("/services//service-settings/email-branding/nhs", methods=['GET', 'POST']) +@user_has_permissions('manage_service') +def email_branding_nhs(service_id): + if request.method == 'POST': + create_email_branding_zendesk_ticket('nhs') + + flash('Thanks for your branding request. We’ll get back to you within one working day.', 'default') + return redirect(url_for('.service_settings', service_id=current_service.id)) + + return render_template('views/service-settings/branding/email-branding-nhs.html') + + +@main.route("/services//service-settings/email-branding/organisation", methods=['GET', 'POST']) +@user_has_permissions('manage_service') +def email_branding_organisation(service_id): + if request.method == 'POST': + create_email_branding_zendesk_ticket('organisation') + + flash('Thanks for your branding request. We’ll get back to you within one working day.', 'default') + return redirect(url_for('.service_settings', service_id=current_service.id)) + + return render_template('views/service-settings/branding/email-branding-organisation.html') + + +@main.route("/services//service-settings/email-branding/something-else", methods=['GET', 'POST']) +@user_has_permissions('manage_service') +def email_branding_something_else(service_id): + form = SomethingElseBrandingForm() + + if form.validate_on_submit(): + create_email_branding_zendesk_ticket('something_else', detail=form.something_else.data) + + flash('Thanks for your branding request. We’ll get back to you within one working day.', 'default') + return redirect(url_for('.service_settings', service_id=current_service.id)) + + return render_template('views/service-settings/branding/email-branding-something-else.html', form=form) + + @main.route("/services//branding-request/letter", methods=['GET', 'POST']) @user_has_permissions('manage_service') def letter_branding_request(service_id): diff --git a/app/navigation.py b/app/navigation.py index ea790910f..a928000b4 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -219,7 +219,11 @@ class MainNavigation(Navigation): 'settings': { 'add_organisation_from_gp_service', 'add_organisation_from_nhs_local_service', + 'email_branding_govuk', + 'email_branding_nhs', + 'email_branding_organisation', 'email_branding_request', + 'email_branding_something_else', 'estimate_usage', 'letter_branding_request', 'link_service_to_organisation', diff --git a/app/templates/views/service-settings/branding/email-branding-govuk.html b/app/templates/views/service-settings/branding/email-branding-govuk.html new file mode 100644 index 000000000..55efd6095 --- /dev/null +++ b/app/templates/views/service-settings/branding/email-branding-govuk.html @@ -0,0 +1,43 @@ +{% extends "withnav_template.html" %} +{% from "components/form.html" import form_wrapper %} +{% from "components/back-link/macro.njk" import govukBackLink %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/page-header.html" import page_header %} + +{% block service_page_title %} + Before you request new branding +{% endblock %} + +{% block backLink %} + {{ govukBackLink({ + "href": url_for('.email_branding_request', service_id=current_service.id) + }) }} +{% endblock %} + +{% block maincolumn_content %} + + {{ page_header('Before you request new branding') }} + +

Check that your new branding matches the rest of your service.

+ +

You can use the GOV.UK logo on your emails if:

+
    +
  • your website looks like GOV.UK
  • +
  • your email links to a website that looks like GOV.UK
  • +
  • people get an email from your service after using GOV.UK
  • +
+ +

+ You cannot use GOV.UK branding if your organisation is + independent + from government. +

+ +

We’ll email you once your branding’s ready to use, or if we need any more information.

+ + {% call form_wrapper() %} + {{ page_footer('Request new branding', button_name='branding_choice', button_value=('govuk_and_org' if with_org == 'True' else 'govuk')) }} + {% endcall %} + +{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-nhs.html b/app/templates/views/service-settings/branding/email-branding-nhs.html new file mode 100644 index 000000000..015dd68a4 --- /dev/null +++ b/app/templates/views/service-settings/branding/email-branding-nhs.html @@ -0,0 +1,33 @@ +{% extends "withnav_template.html" %} +{% from "components/form.html" import form_wrapper %} +{% from "components/back-link/macro.njk" import govukBackLink %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/page-header.html" import page_header %} + +{% block service_page_title %} + Before you request new branding +{% endblock %} + +{% block backLink %} + {{ govukBackLink({ + "href": url_for('.email_branding_request', service_id=current_service.id) + }) }} +{% endblock %} + +{% block maincolumn_content %} + + {{ page_header('Before you request new branding') }} + +

+ Check that your service is allowed to use the NHS identity. +

+ +

Your new branding should match the rest of your service.

+ +

We’ll email you once your branding’s ready to use, or if we need any more information.

+ + {% call form_wrapper() %} + {{ page_footer('Request new branding') }} + {% endcall %} + +{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-options.html b/app/templates/views/service-settings/branding/email-branding-options.html index 59f630bb5..020fc86c6 100644 --- a/app/templates/views/service-settings/branding/email-branding-options.html +++ b/app/templates/views/service-settings/branding/email-branding-options.html @@ -1,5 +1,5 @@ {% extends "withnav_template.html" %} -{% from "components/radios.html" import radio, conditional_radio_panel %} +{% from "components/radios.html" import radio %} {% from "components/select-input.html" import select_wrapper %} {% from "components/textbox.html" import textbox %} {% from "components/page-header.html" import page_header %} @@ -31,33 +31,27 @@

{% endif %} - {% call form_wrapper() %} - {% if form.something_else_is_only_option %} - {{ textbox( - form.something_else, - hint='Include links to your brand guidelines or examples of how to use your branding', - width='1-1', - ) }} - {% else %} - {% call select_wrapper(form.options) %} - {% for option in form.options %} - {{ radio(option, data_target='panel-something-else' if option.data == form.FALLBACK_OPTION_VALUE else '') }} - {% endfor %} - {% endcall %} - {% call conditional_radio_panel('panel-something-else') %} + {% if form.something_else_is_only_option %} + {% call form_wrapper() %} {{ textbox( form.something_else, hint='Include links to your brand guidelines or examples of how to use your branding', width='1-1', - autosize=True, ) }} - {% endcall %} - {% endif %} -

- We’ll email you once your branding’s ready to use, or if we need any - more information. -

- {{ page_footer('Request new branding') }} - {% endcall %} +

+ We’ll email you when your branding is ready, or if we need any more information. +

+ {{ page_footer('Request new branding') }} + {% endcall %} + {% else %} + {% call form_wrapper() %} + {% call select_wrapper(form.options) %} + {% for option in form.options %} + {{ radio(option) }} + {% endfor %} + {% endcall %} + {{ page_footer('Continue') }} + {% endcall %} + {% endif %} {% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-organisation.html b/app/templates/views/service-settings/branding/email-branding-organisation.html new file mode 100644 index 000000000..94146ac4b --- /dev/null +++ b/app/templates/views/service-settings/branding/email-branding-organisation.html @@ -0,0 +1,31 @@ +{% extends "withnav_template.html" %} +{% from "components/form.html" import form_wrapper %} +{% from "components/back-link/macro.njk" import govukBackLink %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/page-header.html" import page_header %} + +{% block service_page_title %} + When you request new branding +{% endblock %} + +{% block backLink %} + {{ govukBackLink({ + "href": url_for('.email_branding_request', service_id=current_service.id) + }) }} +{% endblock %} + +{% block maincolumn_content %} + + {{ page_header('When you request new branding') }} + +

We’ll check if we already have the {{organisation}} logo.

+ +

If we do, we’ll let you know when your new branding is ready to use.

+ +

If we don’t, we’ll email you to ask for more information.

+ + {% call form_wrapper() %} + {{ page_footer('Request new branding') }} + {% endcall %} + +{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-something-else.html b/app/templates/views/service-settings/branding/email-branding-something-else.html new file mode 100644 index 000000000..4e31a2f74 --- /dev/null +++ b/app/templates/views/service-settings/branding/email-branding-something-else.html @@ -0,0 +1,32 @@ +{% extends "withnav_template.html" %} +{% from "components/form.html" import form_wrapper %} +{% from "components/back-link/macro.njk" import govukBackLink %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/page-header.html" import page_header %} +{% from "components/textbox.html" import textbox %} + +{% block service_page_title %} + Describe the branding you want +{% endblock %} + +{% block backLink %} + {{ govukBackLink({ + "href": url_for('.email_branding_request', service_id=current_service.id) + }) }} +{% endblock %} + +{% block maincolumn_content %} + + {{ page_header('Describe the branding you want') }} + + {% call form_wrapper() %} + {{ textbox( + form.something_else, + hint='Include links to your brand guidelines or examples of how to use your branding', + width='1-1', + ) }} +

We’ll email you when your branding is ready, or if we need any more information.

+ {{ page_footer('Request new branding') }} + {% endcall %} + +{% endblock %} diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index f8f5b172b..9d7534614 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -4750,7 +4750,6 @@ def test_update_service_organisation_does_not_update_if_same_value( assert mock_update_service_organisation.called is False -@pytest.mark.parametrize('branding_type', ['email', 'letter']) @pytest.mark.parametrize('organisation_type, expected_options', ( ('central', None), ('local', None), @@ -4769,21 +4768,77 @@ def test_update_service_organisation_does_not_update_if_same_value( ('emergency_service', None), ('other', None), )) -def test_show_branding_request_page_when_no_branding_is_set( - mocker, +def test_show_email_branding_request_page_when_no_branding_is_set( service_one, client_request, mock_get_email_branding, mock_get_letter_branding_by_id, organisation_type, expected_options, - branding_type ): - service_one['{}_branding'.format(branding_type)] = None + service_one['email_branding'] = None service_one['organisation_type'] = organisation_type page = client_request.get( - f'.{branding_type}_branding_request', service_id=SERVICE_ONE_ID + '.email_branding_request', service_id=SERVICE_ONE_ID + ) + + assert mock_get_email_branding.called is False + assert mock_get_letter_branding_by_id.called is False + + button_text = normalize_spaces(page.select_one('.page-footer button').text) + + if expected_options: + assert [ + ( + radio['value'], + page.select_one('label[for={}]'.format(radio['id'])).text.strip() + ) + for radio in page.select('input[type=radio]') + ] == expected_options + + assert button_text == 'Continue' + else: + assert page.select_one( + 'textarea' + )['name'] == ( + 'something_else' + ) + assert not page.select('.conditional-radios-panel') + assert button_text == 'Request new branding' + + +@pytest.mark.parametrize('organisation_type, expected_options', ( + ('central', None), + ('local', None), + ('nhs_central', [ + ('nhs', 'NHS'), + ('something_else', 'Something else'), + ]), + ('nhs_local', [ + ('nhs', 'NHS'), + ('something_else', 'Something else'), + ]), + ('nhs_gp', [ + ('nhs', 'NHS'), + ('something_else', 'Something else'), + ]), + ('emergency_service', None), + ('other', None), +)) +def test_letter_show_branding_request_page_when_no_branding_is_set( + service_one, + client_request, + mock_get_email_branding, + mock_get_letter_branding_by_id, + organisation_type, + expected_options, +): + service_one['letter_branding'] = None + service_one['organisation_type'] = organisation_type + + page = client_request.get( + '.letter_branding_request', service_id=SERVICE_ONE_ID ) assert mock_get_email_branding.called is False @@ -4870,6 +4925,13 @@ def test_show_branding_request_page_when_no_branding_is_set_but_organisation_exi for radio in page.select('input[type=radio]') ] == expected_options + button_text = normalize_spaces(page.select_one('.page-footer button').text) + + if branding_type == 'email': + assert button_text == 'Continue' + else: + assert button_text == 'Request new branding' + @pytest.mark.parametrize('organisation_type, expected_options, branding_type', ( ('central', [ @@ -5043,58 +5105,103 @@ def test_show_branding_request_page_when_branding_is_same_as_org( assert page.select_one('textarea')['name'] == 'something_else' -@pytest.mark.parametrize('data, requested_branding', ( +@pytest.mark.parametrize('data, org_type, endpoint, expect_with_org_query_param', ( ( { 'options': 'govuk', }, - 'GOV.UK', + 'central', + 'main.email_branding_govuk', + False ), ( { 'options': 'govuk', 'something_else': 'ignored', }, - 'GOV.UK', + 'central', + 'main.email_branding_govuk', + False + ), + ( + { + 'options': 'govuk_and_org', + }, + 'central', + 'main.email_branding_govuk', + True + ), + ( + { + 'options': 'organisation', + }, + 'central', + 'main.email_branding_organisation', + False ), ( { 'options': 'something_else', - 'something_else': 'Homer Simpson' }, - 'Something else\n\nHomer Simpson' + 'central', + 'main.email_branding_something_else', + False + ), + ( + { + 'options': 'nhs', + }, + 'nhs_local', + 'main.email_branding_nhs', + False ), )) -@pytest.mark.parametrize('org_name, expected_organisation', ( - (None, 'Can’t tell (domain is user.gov.uk)'), - ('Test Organisation', 'Test Organisation'), -)) -def test_submit_email_branding_request( +def test_submit_email_branding_request_when_something_else_is_not_the_only_option( client_request, service_one, mocker, + mock_get_email_branding, + organisation_one, data, - requested_branding, + org_type, + endpoint, + expect_with_org_query_param, +): + organisation_one['organisation_type'] = org_type + service_one['email_branding'] = sample_uuid() + service_one['organisation'] = organisation_one + + mocker.patch( + 'app.organisations_client.get_organisation', + return_value=organisation_one, + ) + + client_request.post( + '.email_branding_request', + service_id=SERVICE_ONE_ID, + _data=data, + _expected_status=302, + _expected_redirect=url_for( + endpoint, + service_id=SERVICE_ONE_ID, + with_org=(True if expect_with_org_query_param else None), + _external=True, + ) + ) + + +def test_submit_email_branding_request_when_something_else_is_only_option( + client_request, + service_one, + mocker, mock_get_service_settings_page_common, mock_get_email_branding, no_reply_to_email_addresses, no_letter_contact_blocks, single_sms_sender, - org_name, - 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, - ) - mocker.patch( - 'app.organisations_client.get_organisation', - return_value=organisation_json(name=org_name), - ) + service_one['organisation_type'] = 'local' mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__') mock_send_ticket_to_zendesk = mocker.patch( @@ -5105,27 +5212,27 @@ def test_submit_email_branding_request( page = client_request.post( '.email_branding_request', service_id=SERVICE_ONE_ID, - _data=data, + _data={'options': 'something_else', 'something_else': 'Homer Simpson'}, _follow_redirects=True, ) mock_create_ticket.assert_called_once_with( ANY, message='\n'.join([ - 'Organisation: {}', + 'Organisation: Can’t tell (domain is user.gov.uk)', 'Service: service one', 'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb', '', '---', 'Current branding: Organisation name', - 'Branding requested: {}\n', - ]).format(expected_organisation, requested_branding), + 'Branding requested: Something else\n\nHomer Simpson\n', + ]), subject='Email branding request - service one', ticket_type='question', user_name='Test User', user_email='test@user.gov.uk', - org_id=organisation_id, - org_type='central', + org_id=None, + org_type='local', service_id=SERVICE_ONE_ID ) mock_send_ticket_to_zendesk.assert_called_once() @@ -5135,26 +5242,37 @@ def test_submit_email_branding_request( ) -@pytest.mark.parametrize('data, error_message', ( - ({'options': 'something_else'}, 'Cannot be empty'), # no data in 'something_else' textbox - ({'options': 'foo'}, 'Select an option'), # no radio button selected -)) -def test_submit_email_branding_request_when_form_has_missing_data( +def test_submit_email_branding_request_when_something_else_is_only_option_and_textbox_is_empty( + client_request, + service_one, + mock_get_email_branding, +): + service_one['email_branding'] = sample_uuid() + service_one['organisation_type'] = 'local' + + page = client_request.post( + '.email_branding_request', service_id=SERVICE_ONE_ID, + _data={'options': 'something_else', 'something_else': ''}, + _follow_redirects=True, + ) + assert page.h1.text == 'Change email branding' + assert normalize_spaces(page.select_one('.error-message').text) == 'Cannot be empty' + + +def test_submit_email_branding_request_when_no_radio_button_is_selected( client_request, service_one, - data, - error_message, mock_get_email_branding, ): service_one['email_branding'] = sample_uuid() page = client_request.post( '.email_branding_request', service_id=SERVICE_ONE_ID, - _data=data, + _data={'options': ''}, _follow_redirects=True, ) assert page.h1.text == 'Change email branding' - assert normalize_spaces(page.select_one('.error-message').text) == error_message + assert normalize_spaces(page.select_one('.error-message').text) == 'Select an option' @pytest.mark.parametrize('org_name, expected_organisation', ( @@ -5322,6 +5440,273 @@ def test_submit_branding_when_something_else_is_only_option( ) in mock_create_ticket.call_args_list[0][1]['message'] +@pytest.mark.parametrize('endpoint, query_param, expected_heading', [ + ('main.email_branding_govuk', False, 'Before you request new branding'), + ('main.email_branding_govuk', True, 'Before you request new branding'), + ('main.email_branding_nhs', False, 'Before you request new branding'), + ('main.email_branding_organisation', False, 'When you request new branding'), +]) +def test_get_email_branding_description_pages(client_request, endpoint, query_param, expected_heading): + page = client_request.get( + endpoint, + service_id=SERVICE_ONE_ID, + with_org=(True if query_param else None) + ) + assert page.h1.text == expected_heading + assert normalize_spaces(page.select_one('.page-footer button').text) == 'Request new branding' + + +def test_get_email_branding_something_else_page(client_request): + page = client_request.get( + 'main.email_branding_something_else', + service_id=SERVICE_ONE_ID, + ) + assert normalize_spaces(page.h1.text) == 'Describe the branding you want' + assert page.select_one('textarea')['name'] == ('something_else') + assert normalize_spaces(page.select_one('.page-footer button').text) == 'Request new branding' + + +@pytest.mark.parametrize('branding_choice, branding_description', [ + ('govuk', 'GOV.UK'), + ('govuk_and_org', 'GOV.UK and organisation one'), +]) +def test_submit_email_branding_request_from_govuk_description_page( + mocker, + client_request, + service_one, + organisation_one, + mock_get_service_settings_page_common, + no_reply_to_email_addresses, + mock_get_email_branding, + single_sms_sender, + branding_choice, + branding_description, +): + mocker.patch( + 'app.organisations_client.get_organisation', + return_value=organisation_one, + ) + mocker.patch( + 'app.models.service.Service.organisation_id', + new_callable=PropertyMock, + return_value=ORGANISATION_ID, + ) + service_one['email_branding'] = sample_uuid() + + 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, + ) + + page = client_request.post( + '.email_branding_govuk', + service_id=SERVICE_ONE_ID, + _data={'branding_choice': branding_choice}, + _follow_redirects=True, + ) + + mock_create_ticket.assert_called_once_with( + ANY, + message='\n'.join([ + 'Organisation: organisation one', + 'Service: service one', + 'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb', + '', + '---', + 'Current branding: Organisation name', + f'Branding requested: {branding_description}\n', + ]), + subject='Email branding request - service one', + ticket_type='question', + user_name='Test User', + 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.' + ) + + +def test_submit_email_branding_request_from_nhs_description_page( + mocker, + client_request, + service_one, + organisation_one, + mock_get_service_settings_page_common, + no_reply_to_email_addresses, + mock_get_email_branding, + single_sms_sender, +): + service_one['email_branding'] = sample_uuid() + service_one['organisation_type'] = 'nhs_local' + + 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, + ) + + page = client_request.post( + '.email_branding_nhs', + service_id=SERVICE_ONE_ID, + _follow_redirects=True, + ) + + mock_create_ticket.assert_called_once_with( + ANY, + message='\n'.join([ + 'Organisation: Can’t tell (domain is user.gov.uk)', + 'Service: service one', + 'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb', + '', + '---', + 'Current branding: Organisation name', + 'Branding requested: NHS\n', + ]), + subject='Email branding request - service one', + ticket_type='question', + user_name='Test User', + user_email='test@user.gov.uk', + org_id=None, + org_type='nhs_local', + 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.' + ) + + +def test_submit_email_branding_request_from_organisation_description_page( + mocker, + client_request, + service_one, + organisation_one, + mock_get_service_settings_page_common, + no_reply_to_email_addresses, + mock_get_email_branding, + single_sms_sender, +): + mocker.patch( + 'app.organisations_client.get_organisation', + return_value=organisation_one, + ) + mocker.patch( + 'app.models.service.Service.organisation_id', + new_callable=PropertyMock, + return_value=ORGANISATION_ID, + ) + service_one['email_branding'] = sample_uuid() + + 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, + ) + + page = client_request.post( + '.email_branding_organisation', + service_id=SERVICE_ONE_ID, + _follow_redirects=True, + ) + + mock_create_ticket.assert_called_once_with( + ANY, + message='\n'.join([ + 'Organisation: organisation one', + 'Service: service one', + 'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb', + '', + '---', + 'Current branding: Organisation name', + 'Branding requested: organisation one\n', + ]), + subject='Email branding request - service one', + ticket_type='question', + user_name='Test User', + 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.' + ) + + +def test_submit_email_branding_something_else_page( + client_request, + mocker, + service_one, + mock_get_service_settings_page_common, + no_reply_to_email_addresses, + mock_get_email_branding, + single_sms_sender, +): + service_one['email_branding'] = sample_uuid() + service_one['organisation_type'] = 'nhs_local' + + 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, + ) + + page = client_request.post( + '.email_branding_something_else', + service_id=SERVICE_ONE_ID, + _data={'something_else': 'Homer Simpson'}, + _follow_redirects=True, + ) + + mock_create_ticket.assert_called_once_with( + ANY, + message='\n'.join([ + 'Organisation: Can’t tell (domain is user.gov.uk)', + 'Service: service one', + 'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb', + '', + '---', + 'Current branding: Organisation name', + 'Branding requested: Something else\n', + 'Homer Simpson\n' + ]), + subject='Email branding request - service one', + ticket_type='question', + user_name='Test User', + user_email='test@user.gov.uk', + org_id=None, + org_type='nhs_local', + 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.' + ) + + +def test_submit_email_branding_something_else_page_shows_error_if_textbox_is_empty( + client_request, +): + page = client_request.post( + '.email_branding_something_else', + service_id=SERVICE_ONE_ID, + _data={'something_else': ''}, + _follow_redirects=True, + ) + assert normalize_spaces(page.h1.text) == 'Describe the branding you want' + assert normalize_spaces(page.select_one('.error-message').text) == 'Cannot be empty' + + def test_service_settings_links_to_branding_request_page_for_letters( mocker, service_one, diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index e30476307..9a3684030 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -111,7 +111,11 @@ EXCLUDED_ENDPOINTS = tuple(map(Navigation.get_endpoint_with_blueprint, { 'edit_user_mobile_number', 'edit_user_permissions', 'email_branding', + 'email_branding_govuk', + 'email_branding_nhs', + 'email_branding_organisation', 'email_branding_request', + 'email_branding_something_else', 'email_not_received', 'email_template', 'error',