Skip to content

Commit bb3e9dd

Browse files
committed
Handle Werkzeug 2.1.0 change to Response.autocorrect_location_header.
Fixes python-restx#426 pallets/werkzeug#2352 changed the default value of Response.autocorrect_location_header from True to False in Werkzeug >= 2.1.0. tests/legacy/test_api_legacy.py::APITest::test_redirect depended upon Response.autocorrect_location_header being True. Change `test_redirect()` to explicitly set `Response.autocorrect_location_header` to `False`, for backwards compatibility, and change the expected result for the test from an absolute URL to the relative URL.
1 parent 88497ce commit bb3e9dd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/legacy/test_api_legacy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,17 @@ def get(self):
373373
def test_redirect(self, api, client):
374374
class FooResource(restx.Resource):
375375
def get(self):
376-
return redirect("/")
376+
response = redirect("/")
377+
# Response.autocorrect_location_header = False is now the default in Werkzeug >= 2.1
378+
# It is explicitly set here so the test remains backwards compatible with previous versions of Werkzeug.
379+
response.autocorrect_location_header = False
380+
return response
377381

378382
api.add_resource(FooResource, "/api")
379383

380384
resp = client.get("/api")
381385
assert resp.status_code == 302
382-
assert resp.headers["Location"] == "http://localhost/"
386+
assert resp.headers["Location"] == "/"
383387

384388
def test_calling_owns_endpoint_before_api_init(self):
385389
api = restx.Api()

0 commit comments

Comments
 (0)