forked from orbit-oss/flask
Register errorhandlers for Exceptions
Allow a default errorhandler by registering an errorhandler for HTTPException tests included
This commit is contained in:
parent
c8e56d5807
commit
668061a5fc
2 changed files with 34 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from werkzeug.exceptions import Forbidden, InternalServerError
|
||||
from werkzeug.exceptions import Forbidden, InternalServerError, HTTPException, NotFound
|
||||
import flask
|
||||
|
||||
|
||||
|
|
@ -32,6 +32,29 @@ def test_error_handler_no_match():
|
|||
assert c.get('/keyerror').data == b'KeyError'
|
||||
|
||||
|
||||
def test_default_error_handler():
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
@app.errorhandler(HTTPException)
|
||||
def catchall_errorhandler(e):
|
||||
assert isinstance(e, HTTPException)
|
||||
assert isinstance(e, NotFound)
|
||||
return 'default'
|
||||
|
||||
@app.errorhandler(Forbidden)
|
||||
def catchall_errorhandler(e):
|
||||
assert isinstance(e, Forbidden)
|
||||
return 'forbidden'
|
||||
|
||||
@app.route('/forbidden')
|
||||
def forbidden():
|
||||
raise Forbidden()
|
||||
|
||||
c = app.test_client()
|
||||
assert c.get('/undefined').data == b'default'
|
||||
assert c.get('/forbidden').data == b'forbidden'
|
||||
|
||||
|
||||
def test_error_handler_subclass():
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue