wrap call to json in try-except to make tests pass

This commit is contained in:
Miroslav Batchkarov 2017-06-07 09:57:07 +01:00
parent 199fa50a9d
commit 3f22b644b6

View File

@ -1,4 +1,5 @@
import traceback
from json import JSONDecodeError
from sanic.log import log
@ -26,9 +27,14 @@ class SanicTestClient:
session, method.lower())(url, *args, **kwargs) as response:
try:
response.text = await response.text()
response.json = await response.json()
except UnicodeDecodeError as e:
response.text = None
try:
response.json = await response.json()
except (JSONDecodeError, UnicodeDecodeError):
response.json = None
response.body = await response.read()
return response