Merge pull request #4496 from pallets/werkzeug-relative-redirect
Before adoption: this commit came in with the history the project adopted, so no landing records it.
update tests to use relative redirects
authored by David Lord · committed by GitHub · parents ce7b884, 81c7ff7 · Browse files · 6 files·+20 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+20 added−9 removed
- tests:+11 added−5 removed
- other:+9 added−4 removed
Provenance
- Commit
425a626- Tree
78f8982- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
ce7b884- Parent 2
81c7ff7
6 files changed+20 added−9 removed
modified:docs/tutorial/tests.rst+4 added-4 removed
264 unmodified lines265 assert client.get('/auth/register').status_code == 200266 response = client.post(267 '/auth/register', data={'username': 'a', 'password': 'a'}268 )269- assert 'http://localhost/auth/login' == response.headers['Location']269+ assert response.headers["Location"] == "/auth/login"270 271 with app.app_context():272 assert get_db().execute(273 "SELECT * FROM user WHERE username = 'a'",44 unmodified lines318 319 def test_login(client, auth):320 assert client.get('/auth/login').status_code == 200321 response = auth.login()322- assert response.headers['Location'] == 'http://localhost/'322+ assert response.headers["Location"] == "/"323 324 with client:325 client.get('/')326 assert session['user_id'] == 176 unmodified lines403 '/1/delete',404 ))405 def test_login_required(client, path):406 response = client.post(path)407- assert response.headers['Location'] == 'http://localhost/auth/login'407+ assert response.headers["Location"] == "/auth/login"408 409 410 def test_author_required(app, client, auth):411 # change the post author to another user66 unmodified lines478 479 def test_delete(client, auth, app):480 auth.login()481 response = client.post('/1/delete')482- assert response.headers['Location'] == 'http://localhost/'482+ assert response.headers["Location"] == "/"483 484 with app.app_context():485 db = get_db()486 post = db.execute('SELECT * FROM post WHERE id = 1').fetchone()75 unmodified linesmodified:examples/tutorial/tests/test_auth.py+2 added-2 removed
9 unmodified lines10 assert client.get("/auth/register").status_code == 20011 12 # test that successful registration redirects to the login page13 response = client.post("/auth/register", data={"username": "a", "password": "a"})14- assert "http://localhost/auth/login" == response.headers["Location"]14+ assert response.headers["Location"] == "/auth/login"15 16 # test that the user was inserted into the database17 with app.app_context():18 assert (22 unmodified lines41 assert client.get("/auth/login").status_code == 20042 43 # test that successful login redirects to the index page44 response = auth.login()45- assert response.headers["Location"] == "http://localhost/"45+ assert response.headers["Location"] == "/"46 47 # login request set the user_id in the session48 # check that the user is loaded from the session49 with client:20 unmodified linesmodified:examples/tutorial/tests/test_blog.py+2 added-2 removed
17 unmodified lines18 19 @pytest.mark.parametrize("path", ("/create", "/1/update", "/1/delete"))20 def test_login_required(client, path):21 response = client.post(path)22- assert response.headers["Location"] == "http://localhost/auth/login"22+ assert response.headers["Location"] == "/auth/login"23 24 25 def test_author_required(app, client, auth):26 # change the post author to another user47 unmodified lines74 75 def test_delete(client, auth, app):76 auth.login()77 response = client.post("/1/delete")78- assert response.headers["Location"] == "http://localhost/"78+ assert response.headers["Location"] == "/"79 80 with app.app_context():81 db = get_db()82 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()1 unmodified linemodified:src/flask/wrappers.py+2 added
153 unmodified lines154 default_mimetype = "text/html"155 156 json_module = json157 158+ autocorrect_location_header = False159+160 @property161 def max_cookie_size(self) -> int: # type: ignore162 """Read-only view of the :data:`MAX_COOKIE_SIZE` config key.163 8 unmodified linesmodified:tests/test_regression.py+7 added-1 removed
17 unmodified lines18 raise Foo()19 20 with app.test_client() as c:21 rv = c.get("/")22- assert rv.headers["Location"] == "http://localhost/test"22+ location_parts = rv.headers["Location"].rpartition("/")23+24+ if location_parts[0]:25+ # For older Werkzeug that used absolute redirects.26+ assert location_parts[0] == "http://localhost"27+28+ assert location_parts[2] == "test"29 rv = c.get("/test")30 assert rv.data == b"42"modified:CHANGES.rst+3 added
50 unmodified lines51 precise types and decorate the same function multiple times.52 :issue:`4095, 4295, 4297`53 - Fix typing for ``__exit__`` methods for better compatibility with54 ``ExitStack``. :issue:`4474`55+- From Werkzeug, for redirect responses the ``Location`` header URL56+ will remain relative, and exclude the scheme and domain, by default.57+ :pr:`4496`58 59 60 Version 2.0.361 -------------1199 unmodified lines