1. try...catch aiohttp encode response body to text in test_client
2. add tests static binary file
This commit is contained in:
parent
1456b128d2
commit
fdbf452ced
|
@ -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
BIN
tests/static/python.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user