1. try...catch aiohttp encode response body to text in test_client

2. add tests static binary file
This commit is contained in:
skytoup 2017-03-23 15:22:00 +08:00
parent 1456b128d2
commit fdbf452ced
3 changed files with 5 additions and 2 deletions

View File

@ -22,7 +22,10 @@ class SanicTestClient:
cookies=cookies, connector=conn) as session: cookies=cookies, connector=conn) as session:
async with getattr( async with getattr(
session, method.lower())(url, *args, **kwargs) as response: session, method.lower())(url, *args, **kwargs) as response:
try:
response.text = await response.text() response.text = await response.text()
except UnicodeDecodeError as e:
response.text = None
response.body = await response.read() response.body = await response.read()
return response return response

BIN
tests/static/python.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -25,7 +25,7 @@ def get_file_content(static_file_directory, file_name):
return file.read() return file.read()
@pytest.mark.parametrize('file_name', ['test.file', 'decode me.txt']) @pytest.mark.parametrize('file_name', ['test.file', 'decode me.txt', 'python.png'])
def test_static_file(static_file_directory, file_name): def test_static_file(static_file_directory, file_name):
app = Sanic('test_static') app = Sanic('test_static')
app.static( app.static(