mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
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. https://github.com/alphagov/notifications-admin/blob/9111a7fc86b4ed2f88f9f913c0ea5bfe98f20ead/tests/app/utils/test_user.py#L130-L138 2. https://github.com/alphagov/notifications-admin/blob/9111a7fc86b4ed2f88f9f913c0ea5bfe98f20ead/app/main/views/sign_in.py#L86
This commit is contained in:
@@ -24,9 +24,10 @@ def _test_permissions(
|
|||||||
decorated_index()
|
decorated_index()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if (
|
response = decorated_index()
|
||||||
decorated_index().location != '/sign-in?next=%2F' or
|
if not (
|
||||||
decorated_index().status_code != 302
|
response.location.startswith('/sign-in?next=') and
|
||||||
|
response.status_code == 302
|
||||||
):
|
):
|
||||||
pytest.fail("Failed to throw a forbidden or unauthorised exception")
|
pytest.fail("Failed to throw a forbidden or unauthorised exception")
|
||||||
except (Forbidden, Unauthorized):
|
except (Forbidden, Unauthorized):
|
||||||
|
|||||||
Reference in New Issue
Block a user