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

Function test_blueprint_specific_error_handling

tests/test_blueprints.py:8–43  ·  tests/test_blueprints.py::test_blueprint_specific_error_handling
(app, client)

Source from the content-addressed store, hash-verified

6
7
8def test_blueprint_specific_error_handling(app, client):
9 frontend = flask.Blueprint(class="st">"frontend", __name__)
10 backend = flask.Blueprint(class="st">"backend", __name__)
11 sideend = flask.Blueprint(class="st">"sideend", __name__)
12
13 @frontend.errorhandler(403)
14 def frontend_forbidden(e):
15 return class="st">"frontend says no", 403
16
17 @frontend.route(class="st">"/frontend-no")
18 def frontend_no():
19 flask.abort(403)
20
21 @backend.errorhandler(403)
22 def backend_forbidden(e):
23 return class="st">"backend says no", 403
24
25 @backend.route(class="st">"/backend-no")
26 def backend_no():
27 flask.abort(403)
28
29 @sideend.route(class="st">"/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 class="st">"application itself says no", 403
40
41 assert client.get(class="st">"/frontend-no").data == bclass="st">"frontend says no"
42 assert client.get(class="st">"/backend-no").data == bclass="st">"backend says no"
43 assert client.get(class="st">"/what-is-a-sideend").data == bclass="st">"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