Added a Forbidden exception

Also added a small test.
This commit is contained in:
François KUBLER 2017-06-23 16:44:57 +02:00
parent b5369e611c
commit 2848d7c80e
2 changed files with 17 additions and 1 deletions

View File

@ -194,6 +194,11 @@ class ContentRangeError(SanicException):
}
@add_status_code(403)
class Forbidden(SanicException):
pass
class InvalidRangeType(ContentRangeError):
pass

View File

@ -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')