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

Function test_http_error_subclass_handling

tests/test_basic.py:960–989  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

958
959
960def test_http_error_subclass_handling(app, client):
961 class ForbiddenSubclass(Forbidden):
962 pass
963
964 @app.errorhandler(ForbiddenSubclass)
965 def handle_forbidden_subclass(e):
966 assert isinstance(e, ForbiddenSubclass)
967 return "banana"
968
969 @app.errorhandler(403)
970 def handle_403(e):
971 assert not isinstance(e, ForbiddenSubclass)
972 assert isinstance(e, Forbidden)
973 return "apple"
974
975 @app.route("/1")
976 def index1():
977 raise ForbiddenSubclass()
978
979 @app.route("/2")
980 def index2():
981 flask.abort(403)
982
983 @app.route("/3")
984 def index3():
985 raise Forbidden()
986
987 assert client.get("/1").data == b"banana"
988 assert client.get("/2").data == b"apple"
989 assert client.get("/3").data == b"apple"
990
991
992def test_errorhandler_precedence(app, client):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected