| 1027 | [(False, None, True, True), (True, None, False, True), (False, True, False, False)], |
| 1028 | ) |
| 1029 | def 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 | |
| 1060 | def test_trapping_of_all_http_exceptions(app, client): |