MCPcopy Create free account
hub / github.com/pallets/flask / test_trap_bad_request_key_error

Function test_trap_bad_request_key_error

tests/test_basic.py:1029–1057  ·  view source on GitHub ↗
(app, client, debug, trap, expect_key, expect_abort)

Source from the content-addressed store, hash-verified

1027 [(False, None, True, True), (True, None, False, True), (False, True, False, False)],
1028)
1029def test_trap_bad_request_key_error(app, client, debug, trap, expect_key, expect_abort):
1030 app.config["DEBUG"] = debug
1031 app.config["TRAP_BAD_REQUEST_ERRORS"] = trap
1032
1033 @app.route("/key")
1034 def fail():
1035 flask.request.form["missing_key"]
1036
1037 @app.route("/abort")
1038 def allow_abort():
1039 flask.abort(400)
1040
1041 if expect_key:
1042 rv = client.get("/key")
1043 assert rv.status_code == 400
1044 assert b"missing_key" not in rv.data
1045 else:
1046 with pytest.raises(KeyError) as exc_info:
1047 client.get("/key")
1048
1049 assert exc_info.errisinstance(BadRequest)
1050 assert "missing_key" in exc_info.value.get_description()
1051
1052 if expect_abort:
1053 rv = client.get("/abort")
1054 assert rv.status_code == 400
1055 else:
1056 with pytest.raises(BadRequest):
1057 client.get("/abort")
1058
1059
1060def test_trapping_of_all_http_exceptions(app, client):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected