1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-11-25 23:58:18 +01:00

tests/test_api.py: Use response.text instead of content

Falcon's response content is raw bytes, while its text is a string.
Let's use the latter so we can use json.loads() in Python 3.5, 3.6,
and 3.7 with the same code.

See: https://falcon.readthedocs.io/en/stable/api/testing.html
This commit is contained in:
Alan Orth 2018-11-11 17:01:17 +02:00
parent d94134f80a
commit 556c5ae088
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9

View File

@ -23,12 +23,7 @@ def test_get_item(client):
'''Test requesting a single item.''' '''Test requesting a single item.'''
response = client.simulate_get('/item/17') response = client.simulate_get('/item/17')
response_doc = json.loads(response.text)
# 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['downloads'], int)
assert isinstance(response_doc['id'], int) assert isinstance(response_doc['id'], int)