From e56745721610aedcb26cf8acbfc8fa923791efed Mon Sep 17 00:00:00 2001 From: Ryan Grundy Date: Wed, 17 Apr 2024 10:25:11 +0100 Subject: [PATCH] Update pre validation step to render template instead of redirect --- rh_ui/views/start.py | 4 ++-- tests/unit/views/test_start.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rh_ui/views/start.py b/rh_ui/views/start.py index c2964d7..470ffee 100644 --- a/rh_ui/views/start.py +++ b/rh_ui/views/start.py @@ -1,7 +1,7 @@ import logging import re -from flask import Blueprint, request, flash, g, redirect, current_app, render_template, url_for +from flask import Blueprint, request, flash, g, redirect, current_app, render_template from flask.typing import ResponseReturnValue from requests import Response, HTTPError from structlog import wrap_logger @@ -29,7 +29,7 @@ def start_post(): uac = request.form.get('uac').upper().replace(' ', '') if error := pre_check_uac(uac): flash(error) - return redirect(url_for('i18n.start_bp.start_get')) + return render_template("start.html"), 422 token_response = get_eq_token(uac, g.lang_code) if error_response := handle_token_error_response(token_response): diff --git a/tests/unit/views/test_start.py b/tests/unit/views/test_start.py index 5122d80..e34147d 100644 --- a/tests/unit/views/test_start.py +++ b/tests/unit/views/test_start.py @@ -36,14 +36,14 @@ def test_en_enter_uac_success(test_client): def test_en_enter_uac_blank(test_client): response = test_client.post(EN_START_ROUTE, data={"uac": ""}, follow_redirects=True) - assert response.status_code == 200 + assert response.status_code == 422 assert 'Enter an access code' in response.text def test_en_enter_uac_invalid_length(test_client): response = test_client.post(EN_START_ROUTE, data={"uac": "testing"}, follow_redirects=True) - assert response.status_code == 200 + assert response.status_code == 422 assert 'Enter a 16-character access code' in response.text @@ -51,7 +51,7 @@ def test_uac_pattern_match_failure(test_client): # When we try to hash a UAC that is an invalid format, then it raises the error response = test_client.post(EN_START_ROUTE, data={"uac": 'testing_uac_err-'}, follow_redirects=True) - assert response.status_code == 200 + assert response.status_code == 422 assert 'Access code not recognised. Enter the code again.' in response.text