MCPcopy
hub / github.com/pallets/flask / test_blueprint_specific_error_handling

Function test_blueprint_specific_error_handling

tests/test_blueprints.py:8–43  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

6
7
8def test_blueprint_specific_error_handling(app, client):
9 frontend = flask.Blueprint("frontend", __name__)
10 backend = flask.Blueprint("backend", __name__)
11 sideend = flask.Blueprint("sideend", __name__)
12
13 @frontend.errorhandler(403)
14 def frontend_forbidden(e):
15 return "frontend says no", 403
16
17 @frontend.route("/frontend-no")
18 def frontend_no():
19 flask.abort(403)
20
21 @backend.errorhandler(403)
22 def backend_forbidden(e):
23 return "backend says no", 403
24
25 @backend.route("/backend-no")
26 def backend_no():
27 flask.abort(403)
28
29 @sideend.route("/what-is-a-sideend")
30 def sideend_no():
31 flask.abort(403)
32
33 app.register_blueprint(frontend)
34 app.register_blueprint(backend)
35 app.register_blueprint(sideend)
36
37 @app.errorhandler(403)
38 def app_forbidden(e):
39 return "application itself says no", 403
40
41 assert client.get("/frontend-no").data == b"frontend says no"
42 assert client.get("/backend-no").data == b"backend says no"
43 assert client.get("/what-is-a-sideend").data == b"application itself says no"
44
45
46def test_blueprint_specific_user_error_handling(app, client):

Callers

nothing calls this directly

Calls 2

register_blueprintMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…