Skip to content

Commit

Permalink
refactor(view): redirect to eligibility unverified
Browse files Browse the repository at this point in the history
otherwise returning the view function directly uses the
same request object, with the recaptcha data from the original
confirm request

this also causes the URL to change from /eligibility/confirm
to /eligibility/unverified (wasn't shown before, but is a valid route)
  • Loading branch information
thekaveman committed Oct 14, 2022
1 parent 4bbaf05 commit aa42012
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
7 changes: 5 additions & 2 deletions benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ROUTE_START = "eligibility:start"
ROUTE_LOGIN = "oauth:login"
ROUTE_CONFIRM = "eligibility:confirm"
ROUTE_UNVERIFIED = "eligibility:unverified"
ROUTE_ENROLLMENT = "enrollment:index"

TEMPLATE_INDEX = "eligibility/index.html"
Expand Down Expand Up @@ -151,6 +152,8 @@ def confirm(request):
eligibility = session.eligibility(request)
return verified(request, [eligibility.name])

unverified_view = reverse(ROUTE_UNVERIFIED)

agency = session.agency(request)
verifier = session.verifier(request)
types_to_verify = verify.typenames_to_verify(agency, verifier)
Expand All @@ -163,7 +166,7 @@ def confirm(request):
if verified_types:
return verified(request, verified_types)
else:
return unverified(request)
return redirect(unverified_view)

# GET/POST for Eligibility API verification
page = viewmodels.Page(
Expand Down Expand Up @@ -204,7 +207,7 @@ def confirm(request):
return TemplateResponse(request, TEMPLATE_CONFIRM, ctx)
# no types were verified
elif len(verified_types) == 0:
return unverified(request)
return redirect(unverified_view)
# type(s) were verified
else:
return verified(request, verified_types)
Expand Down
27 changes: 19 additions & 8 deletions tests/pytest/eligibility/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ROUTE_LOGIN,
ROUTE_CONFIRM,
ROUTE_ENROLLMENT,
ROUTE_UNVERIFIED,
TEMPLATE_INDEX,
TEMPLATE_CONFIRM,
TEMPLATE_UNVERIFIED,
Expand Down Expand Up @@ -222,15 +223,14 @@ def test_confirm_get_oauth_verified(mocker, client, model_EligibilityType, mocke
@pytest.mark.usefixtures(
"mocked_session_agency", "mocked_session_verifier_oauth", "mocked_session_oauth_token", "mocked_session_update"
)
def test_confirm_get_oauth_unverified(mocker, client, mocked_analytics_module):
def test_confirm_get_oauth_unverified(mocker, client):
mocker.patch("benefits.eligibility.verify.eligibility_from_oauth", return_value=[])

path = reverse(ROUTE_CONFIRM)
response = client.get(path)

mocked_analytics_module.returned_fail.assert_called_once()
assert response.status_code == 200
assert response.template_name == TEMPLATE_UNVERIFIED
assert response.status_code == 302
assert response.url == reverse(ROUTE_UNVERIFIED)


@pytest.mark.django_db
Expand Down Expand Up @@ -273,15 +273,14 @@ def test_confirm_post_valid_form_eligibility_error(mocker, client, form_data, mo

@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_eligibility_auth_request")
def test_confirm_post_valid_form_eligibility_unverified(mocker, client, form_data, mocked_analytics_module):
def test_confirm_post_valid_form_eligibility_unverified(mocker, client, form_data):
mocker.patch("benefits.eligibility.verify.eligibility_from_api", return_value=[])

path = reverse(ROUTE_CONFIRM)
response = client.post(path, form_data)

mocked_analytics_module.returned_fail.assert_called_once()
assert response.status_code == 200
assert response.template_name == TEMPLATE_UNVERIFIED
assert response.status_code == 302
assert response.url == reverse(ROUTE_UNVERIFIED)


@pytest.mark.django_db
Expand All @@ -299,3 +298,15 @@ def test_confirm_post_valid_form_eligibility_verified(
mocked_analytics_module.returned_success.assert_called_once()
assert response.status_code == 302
assert response.url == reverse(ROUTE_ENROLLMENT)


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_eligibility_request_session")
def test_unverified(client, mocked_analytics_module):
path = reverse(ROUTE_UNVERIFIED)

response = client.get(path)

mocked_analytics_module.returned_fail.assert_called_once()
assert response.status_code == 200
assert response.template_name == TEMPLATE_UNVERIFIED

0 comments on commit aa42012

Please sign in to comment.