sanic/tests/test_response.py

18 lines
499 B
Python
Raw Normal View History

2016-12-25 02:47:15 +00:00
from random import choice
from sanic import Sanic
from sanic.response import HTTPResponse
def test_response_body_not_a_string():
"""Test when a response body sent from the application is not a string"""
app = Sanic('response_body_not_a_string')
random_num = choice(range(1000))
@app.route('/hello')
async def hello_route(request):
return HTTPResponse(body=random_num)
2017-02-14 19:51:20 +00:00
request, response = app.test_client.get('/hello')
2016-12-25 02:47:15 +00:00
assert response.text == str(random_num)