Work around inconsistent request context in tests

The failing test here[1] does two things:
1. makes a request to /sign-out
2. calls the index route, without actually making a request

This means that when the `login_manager.unauthorized_handler`[2] looks
at Flask’s `request` object it gets the request context from 1., not 2.,
because 2. isn’t actually a request. The means it sets the value of the
`next` parameter to that of the request, not of the index route.

Basically at some point Flask has changed and decided that 2. isn’t a
proper request, so won’t set new request context.

This isn’t a realistic test because nothing would call the index
function directly, it would always be as part of a request to that page.

But to make the minimal change to fix the breaking tests this commit
makes the check a bit more general, i.e. that the redirect is to the
sign in page with any `next` parameter, not a specific `next` parameter.

1. 9111a7fc86/tests/app/utils/test_user.py (L130-L138)
2. 9111a7fc86/app/main/views/sign_in.py (L86)
This commit is contained in:
Chris Hill-Scott
2022-05-27 15:44:29 +01:00
parent fc833c802e
commit 5b5d4af681

View File

@@ -24,9 +24,10 @@ def _test_permissions(
decorated_index()
else:
try:
if (
decorated_index().location != '/sign-in?next=%2F' or
decorated_index().status_code != 302
response = decorated_index()
if not (
response.location.startswith('/sign-in?next=') and
response.status_code == 302
):
pytest.fail("Failed to throw a forbidden or unauthorised exception")
except (Forbidden, Unauthorized):