Skip to content
Myr

avoid triggering setupmethod late in tests

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 a406c29 · Browse files · 1 file+42 added−52 removed
This commit

State

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

Diff stats

1 file+42 added−52 removed

  • tests:+42 added−52 removed

1 file+42 added−52 removed

modified:tests/test_basic.py+42 added-52 removed
327 unmodified lines
328 def index():329 flask.session["testing"] = 42330 return "Hello World"331332 @app.route("/clear")333 def clear():334 flask.session.pop("testing", None)335 return "Goodbye World"336337 rv = client.get("/", "http://www.example.com:8080/test/")338 cookie = rv.headers["set-cookie"].lower()339 assert "domain=.example.com" in cookie340 assert "path=/" in cookie341 assert "secure" in cookie342 assert "httponly" not in cookie343 assert "samesite" in cookie344340 @app.route("/clear")341 def clear():342 flask.session.pop("testing", None)343 return "Goodbye World"344345 rv = client.get("/clear", "http://www.example.com:8080/test/")346 cookie = rv.headers["set-cookie"].lower()347 assert "session=;" in cookie348 assert "domain=.example.com" in cookie
681 unmodified lines
1030 rv = client.get("/E3")1031 assert rv.data == b"E2"103210331034def test_trapping_of_bad_request_key_errors(app, client):1034@pytest.mark.parametrize(1035 ("debug", "trap", "expect_key", "expect_abort"),1036 [(False, None, True, True), (True, None, False, True), (False, True, False, False)],1037)1038def test_trap_bad_request_key_error(app, client, debug, trap, expect_key, expect_abort):1039 app.config["DEBUG"] = debug1040 app.config["TRAP_BAD_REQUEST_ERRORS"] = trap10411042 @app.route("/key")1043 def fail():1044 flask.request.form["missing_key"]10451046 @app.route("/abort")1047 def allow_abort():1048 flask.abort(400)10491050 if expect_key:1043 rv = client.get("/key")1044 assert rv.status_code == 4001045 assert b"missing_key" not in rv.data1046 rv = client.get("/abort")1047 assert rv.status_code == 4001051 rv = client.get("/key")1052 assert rv.status_code == 4001053 assert b"missing_key" not in rv.data1054 else:1055 with pytest.raises(KeyError) as exc_info:1056 client.get("/key")10571049 app.debug = True1050 with pytest.raises(KeyError) as e:1051 client.get("/key")1052 assert e.errisinstance(BadRequest)1053 assert "missing_key" in e.value.get_description()1058 assert exc_info.errisinstance(BadRequest)1059 assert "missing_key" in exc_info.value.get_description()1054 rv = client.get("/abort")1055 assert rv.status_code == 40010601057 app.debug = False1058 app.config["TRAP_BAD_REQUEST_ERRORS"] = True1059 with pytest.raises(KeyError):1060 client.get("/key")1061 with pytest.raises(BadRequest):1062 client.get("/abort")1061 if expect_abort:1062 rv = client.get("/abort")1063 assert rv.status_code == 4001064 else:1065 with pytest.raises(BadRequest):1066 client.get("/abort")106710681069def test_trapping_of_all_http_exceptions(app, client):1070 app.config["TRAP_HTTP_EXCEPTIONS"] = True
593 unmodified lines
1664 rv = client.get("/киртест")1665 assert rv.data == b"Hello World!"166616671664def test_debug_mode_complains_after_first_request(app, client):1668def test_no_setup_after_first_request(app, client):1669 app.debug = True16701671 @app.route("/")1672 def index():
1 unmodified line
16741675 assert not app.got_first_request1676 assert client.get("/").data == b"Awesome"16771674 with pytest.raises(AssertionError) as e:1678 with pytest.raises(AssertionError) as exc_info:1679 app.add_url_rule("/foo", endpoint="late")16801677 assert "A setup function was called" in str(e.value)1681 assert "setup method 'add_url_rule'" in str(exc_info.value)16821679 app.debug = False16831681 @app.route("/foo")1682 def working():1683 return "Meh"16841685 assert client.get("/foo").data == b"Meh"1686 assert app.got_first_request168716881684def test_before_first_request_functions(app, client):1685 got = []16861687 @app.before_first_request
26 unmodified lines
1714 assert app.got_first_request171517161717def test_routing_redirect_debugging(monkeypatch, app, client):1723 @app.route("/foo/", methods=["GET", "POST"])1724 def foo():1725 return "success"1718 app.config["DEBUG"] = True17191727 app.debug = False1728 rv = client.post("/foo", data={}, follow_redirects=True)1720 @app.route("/user/", methods=["GET", "POST"])1721 def user():1722 return flask.request.form["status"]17231724 # default redirect code preserves form data1725 rv = client.post("/user", data={"status": "success"}, follow_redirects=True)1726 assert rv.data == b"success"17271731 app.debug = True17321733 with client:1734 rv = client.post("/foo", data={}, follow_redirects=True)1735 assert rv.data == b"success"1736 rv = client.get("/foo", data={}, follow_redirects=True)1737 assert rv.data == b"success"17381728 # 301 and 302 raise error1729 monkeypatch.setattr(RequestRedirect, "code", 301)17301741 with client, pytest.raises(AssertionError) as e:1742 client.post("/foo", data={})1731 with client, pytest.raises(AssertionError) as exc_info:1732 client.post("/user", data={"status": "error"}, follow_redirects=True)17331744 assert "canonical URL 'http://localhost/foo/'" in str(e.value)1734 assert "canonical URL 'http://localhost/user/'" in str(exc_info.value)173517361737def test_route_decorator_custom_endpoint(app, client):1738 app.debug = True
281 unmodified lines