From d94134f80a23fd6f13f442d33c2a21dabd4d7314 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sun, 11 Nov 2018 16:54:09 +0200 Subject: [PATCH] tests/test_api.py: Try to add workaround for Python 3.5 In Python 3.5 it seems that json.loads() cannot decode a bytes, but it works in Python 3.6 and 3.7. Let's try a workaround to see if we can get it working on both Python 3.5 and 3.6+. See: https://docs.python.org/3.5/library/json.html#json.loads See: https://docs.python.org/3.6/library/json.html#json.loads --- tests/test_api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index ee6f22d..8f0c8fa 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -23,7 +23,12 @@ def test_get_item(client): '''Test requesting a single item.''' response = client.simulate_get('/item/17') - response_doc = json.loads(response.content) + + # response.content is a bytes in Python 3.5 + if isinstance(response.content, bytes): + response_doc = json.loads(response.content.decode('utf-8')) + else: + response_doc = json.loads(response.content) assert isinstance(response_doc['downloads'], int) assert isinstance(response_doc['id'], int)