Skip to content
Myr

Add tests for user-defined exceptions in blueprints

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

authored by Wouter Van Hemel · committed by Wouter Van Hemel · parent b031813 · Browse files · 1 file+33 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+33 added−0 removed

  • other:+33 added−0 removed

1 file+33 added−0 removed

modified:flask/testsuite/blueprints.py+33 added
294 unmodified lines
295 self.assert_equal(c.get('/frontend-no').data, b'frontend says no')296 self.assert_equal(c.get('/backend-no').data, b'backend says no')297 self.assert_equal(c.get('/what-is-a-sideend').data, b'application itself says no')298299 def test_blueprint_specific_user_error_handling(self):300 class MyDecoratorException(Exception):301 pass302 class MyFunctionException(Exception):303 pass304305 blue = flask.Blueprint('blue', __name__)306307 @blue.errorhandler(MyDecoratorException)308 def my_decorator_exception_handler(e):309 self.assert_true(isinstance(e, MyDecoratorException))310 return 'boom'311312 def my_function_exception_handler(e):313 self.assert_true(isinstance(e, MyFunctionException))314 return 'bam'315 blue.register_error_handler(MyFunctionException, my_function_exception_handler)316317 @blue.route('/decorator')318 def blue_deco_test():319 raise MyDecoratorException()320 @blue.route('/function')321 def blue_func_test():322 raise MyFunctionException()323324 app = flask.Flask(__name__)325 app.register_blueprint(blue)326327 c = app.test_client()328329 self.assert_equal(c.get('/decorator').data, b'boom')330 self.assert_equal(c.get('/function').data, b'bam')331332 def test_blueprint_url_definitions(self):333 bp = flask.Blueprint('test', __name__)334335 @bp.route('/foo', defaults={'baz': 42})
488 unmodified lines