Merge pull request #580 from skytoup/master

Fix testing not support binary file
This commit is contained in:
Raphael Deem 2017-03-23 12:22:08 -07:00 committed by GitHub
commit 9774661cfe
3 changed files with 5 additions and 2 deletions

View File

@ -22,7 +22,10 @@ class SanicTestClient:
cookies=cookies, connector=conn) as session:
async with getattr(
session, method.lower())(url, *args, **kwargs) as response:
response.text = await response.text()
try:
response.text = await response.text()
except UnicodeDecodeError as e:
response.text = None
response.body = await response.read()
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()
@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):
app = Sanic('test_static')
app.static(