Skip to content
Myr

Add coverage for Blueprint.app_errorhandler

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This test case registers an application-wise error handler from a Blueprint. Verifies the error handler by aborting the flask app from the application itself as well as from another registered Blueprint.

authored by Randy Liou · committed by Randy Liou · parent f962720 · Browse files · 1 file+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−0 removed

  • tests:+27 added−0 removed

1 file+27 added−0 removed

modified:tests/test_blueprints.py+27 added
89 unmodified lines
9091 assert c.get('/decorator').data == b'boom'92 assert c.get('/function').data == b'bam'9394def test_blueprint_app_error_handling():95 errors = flask.Blueprint('errors', __name__)9697 @errors.app_errorhandler(403)98 def forbidden_handler(e):99 return 'you shall not pass', 403100101 app = flask.Flask(__name__)102103 @app.route('/forbidden')104 def app_forbidden():105 flask.abort(403)106107 forbidden_bp = flask.Blueprint('forbidden_bp', __name__)108109 @forbidden_bp.route('/nope')110 def bp_forbidden():111 flask.abort(403)112113 app.register_blueprint(errors)114 app.register_blueprint(forbidden_bp)115116 c = app.test_client()117118 assert c.get('/forbidden').data == b'you shall not pass'119 assert c.get('/nope').data == b'you shall not pass'120121def test_blueprint_url_definitions():122 bp = flask.Blueprint('test', __name__)123124 @bp.route('/foo', defaults={'baz': 42})
496 unmodified lines