From 1cc087b8def5cb7024b1f96ef346edc6f460eb56 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 6 Oct 2021 12:32:00 +0100 Subject: [PATCH] Move end of tour route into `tour.py` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In https://github.com/alphagov/notifications-admin/pull/3663/files we made specific routes for sending the ‘tour’ text message, rather than sharing the ‘one-off’ routes in `send.py`. This commit moves the final route in the tour journey into `tour.py` as well, which is where I expected to find it when I was looking for it just now. --- app/main/views/send.py | 11 --------- app/main/views/tour.py | 13 +++++++++- tests/app/main/views/test_send.py | 40 ------------------------------- tests/app/main/views/test_tour.py | 40 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index 04356de50..dcf707e8a 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -815,17 +815,6 @@ def start_job(service_id, upload_id): ) -@main.route("/services//end-tour/") -@user_has_permissions('manage_templates') -def go_to_dashboard_after_tour(service_id, example_template_id): - - service_api_client.delete_service_template(service_id, example_template_id) - - return redirect( - url_for('main.service_dashboard', service_id=service_id) - ) - - def fields_to_fill_in(template, prefill_current_user=False): if 'letter' == template.template_type: diff --git a/app/main/views/tour.py b/app/main/views/tour.py index 0cf96b885..63feb90bb 100644 --- a/app/main/views/tour.py +++ b/app/main/views/tour.py @@ -1,6 +1,6 @@ from flask import abort, redirect, render_template, session -from app import current_service, current_user, url_for +from app import current_service, current_user, service_api_client, url_for from app.main import main from app.main.views.send import ( all_placeholders_in_session, @@ -149,3 +149,14 @@ def check_tour_notification(service_id, template_id): back_link=back_link, help='2', ) + + +@main.route("/services//end-tour/") +@user_has_permissions('manage_templates') +def go_to_dashboard_after_tour(service_id, example_template_id): + + service_api_client.delete_service_template(service_id, example_template_id) + + return redirect( + url_for('main.service_dashboard', service_id=service_id) + ) diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 0b64ae2fd..4e7f6c32f 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -3058,46 +3058,6 @@ def test_check_messages_back_link( ) == expected_url(service_id=SERVICE_ONE_ID, template_id=fake_uuid) -def test_shows_link_to_end_tour( - client_request, - mock_get_notification, - fake_uuid, -): - - page = client_request.get( - 'main.view_notification', - service_id=SERVICE_ONE_ID, - notification_id=fake_uuid, - help=3, - ) - - assert page.select(".banner-tour a")[0]['href'] == url_for( - 'main.go_to_dashboard_after_tour', - service_id=SERVICE_ONE_ID, - example_template_id='5407f4db-51c7-4150-8758-35412d42186a', - ) - - -def test_go_to_dashboard_after_tour_link( - logged_in_client, - mocker, - api_user_active, - mock_login, - mock_get_service, - mock_has_permissions, - mock_delete_service_template, - fake_uuid -): - - resp = logged_in_client.get( - url_for('main.go_to_dashboard_after_tour', service_id=fake_uuid, example_template_id=fake_uuid) - ) - - assert resp.status_code == 302 - assert resp.location == url_for("main.service_dashboard", service_id=fake_uuid, _external=True) - mock_delete_service_template.assert_called_once_with(fake_uuid, fake_uuid) - - @pytest.mark.parametrize('num_requested,expected_msg', [ (None, '‘example.csv’ contains 1,234 phone numbers.'), ("0", '‘example.csv’ contains 1,234 phone numbers.'), diff --git a/tests/app/main/views/test_tour.py b/tests/app/main/views/test_tour.py index 506566e17..5453bb475 100644 --- a/tests/app/main/views/test_tour.py +++ b/tests/app/main/views/test_tour.py @@ -616,3 +616,43 @@ def test_check_tour_notification_redirects_to_first_step_if_not_all_placeholders _external=True ), ) + + +def test_shows_link_to_end_tour( + client_request, + mock_get_notification, + fake_uuid, +): + + page = client_request.get( + 'main.view_notification', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + help=3, + ) + + assert page.select(".banner-tour a")[0]['href'] == url_for( + 'main.go_to_dashboard_after_tour', + service_id=SERVICE_ONE_ID, + example_template_id='5407f4db-51c7-4150-8758-35412d42186a', + ) + + +def test_go_to_dashboard_after_tour_link( + logged_in_client, + mocker, + api_user_active, + mock_login, + mock_get_service, + mock_has_permissions, + mock_delete_service_template, + fake_uuid +): + + resp = logged_in_client.get( + url_for('main.go_to_dashboard_after_tour', service_id=fake_uuid, example_template_id=fake_uuid) + ) + + assert resp.status_code == 302 + assert resp.location == url_for("main.service_dashboard", service_id=fake_uuid, _external=True) + mock_delete_service_template.assert_called_once_with(fake_uuid, fake_uuid)