Fix error case where the tour start page is skipped

This was causing us to key error for 'placeholders' being missing in the
session dictionary. This fixes it and sends you back to the start
This commit is contained in:
David McDonald
2020-10-02 12:45:01 +01:00
parent 6f8a2721d9
commit 1f900e74a9
2 changed files with 58 additions and 0 deletions

View File

@@ -49,6 +49,11 @@ def tour_step(service_id, template_id, step_index):
if db_template['template_type'] != 'sms':
abort(404)
if 'placeholders' not in session:
return redirect(url_for(
'.begin_tour', service_id=current_service.id, template_id=template_id
))
template = get_template(
db_template,
current_service,
@@ -119,6 +124,11 @@ def check_tour_notification(service_id, template_id):
show_recipient=True,
)
if 'placeholders' not in session:
return redirect(url_for(
'.begin_tour', service_id=current_service.id, template_id=template_id
))
placeholders = fields_to_fill_in(template, prefill_current_user=True)
if not all_placeholders_in_session(template.placeholders):

View File

@@ -234,6 +234,30 @@ def test_should_403_if_user_does_not_have_send_permissions_for_tour_step(
)
def test_tour_step_redirects_to_tour_start_if_placeholders_doesnt_exist_in_session(
client_request,
mock_get_service_template_with_multiple_placeholders,
service_one,
fake_uuid,
):
with client_request.session_transaction() as session:
assert 'placeholders' not in session
client_request.get(
'main.tour_step',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
step_index=1,
_expected_status=302,
_expected_redirect=url_for(
'main.begin_tour',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
_external=True,
),
)
def test_back_link_from_first_get_tour_step_points_to_tour_start(
client_request,
mock_get_service_template_with_multiple_placeholders,
@@ -518,6 +542,30 @@ def test_back_link_from_check_tour_notification_points_to_last_tour_step(
)
def test_check_tour_notification_redirects_to_tour_start_if_placeholders_doesnt_exist_in_session(
client_request,
mock_get_service_template_with_multiple_placeholders,
service_one,
fake_uuid,
):
with client_request.session_transaction() as session:
assert 'placeholders' not in session
client_request.get(
'main.check_tour_notification',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
step_index=1,
_expected_status=302,
_expected_redirect=url_for(
'main.begin_tour',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
_external=True,
),
)
def test_check_tour_notification_redirects_to_first_step_if_not_all_placeholders_in_session(
client_request,
mock_get_service_template_with_multiple_placeholders,