Added a Forbidden exception
Also added a small test.
This commit is contained in:
parent
b5369e611c
commit
2848d7c80e
|
@ -194,6 +194,11 @@ class ContentRangeError(SanicException):
|
|||
}
|
||||
|
||||
|
||||
@add_status_code(403)
|
||||
class Forbidden(SanicException):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidRangeType(ContentRangeError):
|
||||
pass
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ from bs4 import BeautifulSoup
|
|||
|
||||
from sanic import Sanic
|
||||
from sanic.response import text
|
||||
from sanic.exceptions import InvalidUsage, ServerError, NotFound, abort
|
||||
from sanic.exceptions import InvalidUsage, ServerError, NotFound, Forbidden
|
||||
from sanic.exceptions import abort
|
||||
|
||||
|
||||
class SanicExceptionTestException(Exception):
|
||||
|
@ -26,6 +27,10 @@ def exception_app():
|
|||
def handler_404(request):
|
||||
raise NotFound("OK")
|
||||
|
||||
@app.route('/403')
|
||||
def handler_403(request):
|
||||
raise Forbidden("Forbidden")
|
||||
|
||||
@app.route('/invalid')
|
||||
def handler_invalid(request):
|
||||
raise InvalidUsage("OK")
|
||||
|
@ -91,6 +96,12 @@ def test_not_found_exception(exception_app):
|
|||
assert response.status == 404
|
||||
|
||||
|
||||
def test_forbidden_exception(exception_app):
|
||||
"""Test the built-in Forbidden exception"""
|
||||
request, response = exception_app.test_client.get('/403')
|
||||
assert response.status == 403
|
||||
|
||||
|
||||
def test_handled_unhandled_exception(exception_app):
|
||||
"""Test that an exception not built into sanic is handled"""
|
||||
request, response = exception_app.test_client.get('/divide_by_zero')
|
||||
|
|
Loading…
Reference in New Issue
Block a user