From a578ec23a38c4f2eaa32de7ebe577940875e9c6b Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Thu, 23 Jan 2020 15:54:13 +0000 Subject: [PATCH] Redirect to template after succesful branding request if user entered branding request flow from a template. --- app/main/views/service_settings.py | 9 +-- tests/app/main/views/test_service_settings.py | 71 +++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index c10dde797..4408cd85d 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -1032,8 +1032,8 @@ def link_service_to_organisation(service_id): @main.route("/services//branding-request/", methods=['GET', 'POST']) @user_has_permissions('manage_service') def branding_request(service_id, branding_type): - form = BrandingOptions(current_service, branding_type=branding_type) + from_template = request.args.get('from_template') if branding_type == "email": branding_name = current_service.email_branding_name elif branding_type == "letter": @@ -1065,19 +1065,20 @@ def branding_request(service_id, branding_type): user_name=current_user.name, tags=['notify_action', 'notify_branding'], ) - 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=service_id)) + return redirect(url_for( + '.view_template', service_id=current_service.id, template_id=from_template + ) if from_template else url_for('.service_settings', service_id=current_service.id)) return render_template( 'views/service-settings/branding/branding-options.html', form=form, branding_type=branding_type, branding_name=branding_name, - from_template=request.args.get('from_template') + from_template=from_template ) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index df6aa9173..d1bd6da55 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -4614,6 +4614,39 @@ def test_show_letter_branding_request_page_when_letter_branding_is_set( ] +@pytest.mark.parametrize('branding_type', ['email', 'letter']) +@pytest.mark.parametrize('from_template,back_link_url', [ + (None, '/services/{}/service-settings'.format(SERVICE_ONE_ID),), + (TEMPLATE_ONE_ID, '/services/{}/templates/{}'.format(SERVICE_ONE_ID, TEMPLATE_ONE_ID),) +]) +def test_back_link_on_branding_request_page( + mocker, + service_one, + client_request, + mock_get_email_branding, + mock_get_letter_branding_by_id, + active_user_with_permissions, + from_template, + back_link_url, + branding_type, +): + mocker.patch( + 'app.organisations_client.get_service_organisation', + return_value=organisation_json(), + ) + if from_template: + page = client_request.get( + '.branding_request', service_id=SERVICE_ONE_ID, branding_type=branding_type, from_template=from_template + ) + else: + page = client_request.get( + '.branding_request', service_id=SERVICE_ONE_ID, branding_type=branding_type + ) + + back_link = page.select('a[class=govuk-back-link]') + assert back_link[0].attrs['href'] == back_link_url + + @pytest.mark.parametrize('branding_type', ['email', 'letter']) def test_show_branding_request_page_when_branding_is_same_as_org( mocker, @@ -4819,6 +4852,44 @@ def test_submit_letter_branding_request( ) +@pytest.mark.parametrize('branding_type', ['email', 'letter']) +@pytest.mark.parametrize('from_template', [ + None, + TEMPLATE_ONE_ID +]) +def test_submit_letter_branding_request_redirects_if_from_template_is_set( + client_request, + service_one, + mocker, + mock_get_service_settings_page_common, + mock_get_letter_branding_by_id, + no_reply_to_email_addresses, + no_letter_contact_blocks, + single_sms_sender, + from_template, + branding_type, + +): + mocker.patch('app.organisations_client.get_service_organisation', return_value=None) + mocker.patch('app.main.views.service_settings.zendesk_client.create_ticket', autospec=True) + data = {'options': 'something_else', 'something_else': 'Homer Simpson'} + + if from_template: + client_request.post( + '.branding_request', service_id=SERVICE_ONE_ID, branding_type="letter", from_template=from_template, + _data=data, + _expected_redirect=url_for( + 'main.view_template', service_id=SERVICE_ONE_ID, template_id=from_template, _external=True + ) + ) + else: + client_request.post( + '.branding_request', service_id=SERVICE_ONE_ID, branding_type="letter", + _data=data, + _expected_redirect=url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True) + ) + + @pytest.mark.parametrize('branding_type,current_branding', [ ('email', 'GOV.UK'), ('letter', 'no') ])