Skip to content
Myr

update tests for relative redirects

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent ce7b884 · 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

6 files+20 added−9 removed

modified:docs/tutorial/tests.rst+4 added-4 removed
264 unmodified lines
265 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"270271 with app.app_context():272 assert get_db().execute(273 "SELECT * FROM user WHERE username = 'a'",
44 unmodified lines
318319 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"] == "/"323324 with client:325 client.get('/')326 assert session['user_id'] == 1
76 unmodified lines
403 '/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"408409410 def test_author_required(app, client, auth):411 # change the post author to another user
66 unmodified lines
478479 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"] == "/"483484 with app.app_context():485 db = get_db()486 post = db.execute('SELECT * FROM post WHERE id = 1').fetchone()
75 unmodified lines
modified:examples/tutorial/tests/test_auth.py+2 added-2 removed
9 unmodified lines
10 assert client.get("/auth/register").status_code == 2001112 # 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"1516 # test that the user was inserted into the database17 with app.app_context():18 assert (
22 unmodified lines
41 assert client.get("/auth/login").status_code == 2004243 # test that successful login redirects to the index page44 response = auth.login()45 assert response.headers["Location"] == "http://localhost/"45 assert response.headers["Location"] == "/"4647 # login request set the user_id in the session48 # check that the user is loaded from the session49 with client:
20 unmodified lines
modified:examples/tutorial/tests/test_blog.py+2 added-2 removed
17 unmodified lines
1819@pytest.mark.parametrize("path", ("/create", "/1/update", "/1/delete"))20def 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"232425def test_author_required(app, client, auth):26 # change the post author to another user
47 unmodified lines
7475def 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"] == "/"7980 with app.app_context():81 db = get_db()82 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()
1 unmodified line
modified:src/flask/wrappers.py+2 added
153 unmodified lines
154 default_mimetype = "text/html"155156 json_module = json157158 autocorrect_location_header = False159160 @property161 def max_cookie_size(self) -> int: # type: ignore162 """Read-only view of the :data:`MAX_COOKIE_SIZE` config key.163
8 unmodified lines
modified:tests/test_regression.py+7 added-1 removed
17 unmodified lines
18 raise Foo()1920 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("/")2324 if location_parts[0]:25 # For older Werkzeug that used absolute redirects.26 assert location_parts[0] == "http://localhost"2728 assert location_parts[2] == "test"29 rv = c.get("/test")30 assert rv.data == b"42"
modified:CHANGES.rst+3 added
50 unmodified lines
51 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`585960Version 2.0.361-------------
1199 unmodified lines