From 3f22b644b6d4bfef961065854f0c419481277eba Mon Sep 17 00:00:00 2001 From: Miroslav Batchkarov Date: Wed, 7 Jun 2017 09:57:07 +0100 Subject: [PATCH] wrap call to json in try-except to make tests pass --- sanic/testing.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sanic/testing.py b/sanic/testing.py index 6be79cd0..09554e21 100644 --- a/sanic/testing.py +++ b/sanic/testing.py @@ -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