Skip to content

Commit

Permalink
Update pre validation step to render template instead of redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangrundy7 committed Apr 17, 2024
1 parent d621561 commit e567457
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rh_ui/views/start.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/views/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ 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


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


Expand Down

0 comments on commit e567457

Please sign in to comment.