Merge pull request #223 from r0fls/115

Raise error if response is malformed.
This commit is contained in:
Eli Uriegas
2016-12-24 17:12:17 -08:00
committed by GitHub
2 changed files with 21 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ from json import loads as json_loads, dumps as json_dumps
from sanic import Sanic
from sanic.response import json, text
from sanic.utils import sanic_endpoint_test
from sanic.exceptions import ServerError
# ------------------------------------------------------------ #
@@ -32,6 +33,22 @@ def test_text():
assert response.text == 'Hello'
def test_invalid_response():
app = Sanic('test_invalid_response')
@app.exception(ServerError)
def handler_exception(request, exception):
return text('Internal Server Error.', 500)
@app.route('/')
async def handler(request):
return 'This should fail'
request, response = sanic_endpoint_test(app)
assert response.status == 500
assert response.text == "Internal Server Error."
def test_json():
app = Sanic('test_json')