From fdbf452cedcffd69d99ea9fc95aa9657d83a535e Mon Sep 17 00:00:00 2001 From: skytoup <875766917@qq.com> Date: Thu, 23 Mar 2017 15:22:00 +0800 Subject: [PATCH] 1. try...catch aiohttp encode response body to text in test_client 2. add tests static binary file --- sanic/testing.py | 5 ++++- tests/static/python.png | Bin 0 -> 11252 bytes tests/test_static.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/static/python.png diff --git a/sanic/testing.py b/sanic/testing.py index 4fde428c..1cad6a7b 100644 --- a/sanic/testing.py +++ b/sanic/testing.py @@ -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 diff --git a/tests/static/python.png b/tests/static/python.png new file mode 100644 index 0000000000000000000000000000000000000000..52fda10994c155f51b3f26c566371d44a9ada87b GIT binary patch literal 11252 zcmb7~Q+OR-u=aPfW82A&%{I0h+qP}(*tXTAF&a0v?KHNH#^?WCe>dk`%$jxm&aCH| zHSaGv&Xz5k0?IN*P$Rw-~F0AT2l5f@SOTEF!7ZllsvzjmzA zSGQ~v+wR`XyHem4^OPP1z~f89nNV=BO`?eii>nnwM$17Ky!u7ch6KE(D&u2iJ&vKF z$%&d_z(FSqONu5d%(QkmZlB7jH?Q~vUg)cLOm|TlpBxQ)Y6L#!xnAM_QTTY$@kQ=w zMqy1(iZ!F8z#o&AWdC1YwQEG5k5dAd7Yaf(FT06)JjZQ|uRVwN`pDQU?Q=G`m*u|0 zIjb5Gv}2SK;4}4929sO4ILHhQ*9+L*mxkPTWf5NI=J7fFIQ+S6@>t-E*OJ_b#>J)BT+FdtV_mRl(=xmqPqnbHA6KD)L1j8c z$tJfbZK4`r3@NS#YfWvPFZ(OwDdW}p`euITM#Zsy_S^#(mFeLs^Sq49dVO>061A4E z%-nP4xGZqf*MI}^MS9dc@SV$RrK5GX*z$6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