python3: pass strings to json.loads, for py3.5 compatibility (#41302)

This commit is contained in:
Nicolas Roche 2020-04-06 14:34:58 +02:00
parent b1e015a398
commit e030f6723f
1 changed files with 13 additions and 11 deletions

View File

@ -8,6 +8,8 @@ import mock
from utils import get_tests_file_content, FakedResponse
from django.utils.encoding import force_text
from petale.utils import etag
from petale.models import CUT, Petal
@ -16,7 +18,7 @@ pytestmark = pytest.mark.django_db
def test_authentication_failure(app):
resp = app.get('/api/partner/12345abcde12345abcde12345abcde12/', status=401)
json.loads(resp.content)
json.loads(resp.text)
def test_resource_not_found(app, partner_southpark, cut_kevin_uuid, acl):
@ -60,7 +62,7 @@ def test_access_control_list(app, partner_southpark, cut_kevin_uuid,
#
app.authorization = ('Basic', ('library', 'library'))
payload = json.loads(get_tests_file_content('books.json'))
payload = json.loads(force_text(get_tests_file_content('books.json')))
url = '/api/southpark/%s/loans/' % cut_kevin_uuid
resp = app.put_json(url, params=payload, headers={'If-None-Match': '*'}, status=201)
@ -72,7 +74,7 @@ def test_access_control_list(app, partner_southpark, cut_kevin_uuid,
def test_simple_api(app, partner_southpark, cut_kevin_uuid, acl, petal_invoice):
app.authorization = ('Basic', ('library', 'library'))
payload = json.loads(get_tests_file_content('books.json'))
payload = json.loads(force_text(get_tests_file_content('books.json')))
url = '/api/southpark/%s/loans/' % cut_kevin_uuid
# test create key without content-type
@ -131,7 +133,7 @@ def test_simple_api(app, partner_southpark, cut_kevin_uuid, acl, petal_invoice):
# test key deletion
resp = app.delete(url, status=204)
assert resp.content == b''
assert resp.text == ''
app.get(url, status=404)
# test keys purge
@ -164,7 +166,7 @@ def test_binary_data(app, partner_southpark, cut_kevin_uuid, acl):
payload = {"friends": [{"name": "Token", "age": 10}, {"name": "Kenny", "age": 10}]}
resp = app.put_json(url, params=payload, status=200)
resp = app.get(url, status=200)
data = json.loads(resp.content)
data = json.loads(resp.text)
for datum in data['friends']:
assert datum['name'] in ('Token', 'Kenny')
assert datum['age'] == 10
@ -214,7 +216,7 @@ def test_caching(app, partner_southpark, cut_kevin_uuid, acl):
# try to create the same data
app.authorization = ('Basic', ('cityhall', 'cityhall'))
resp = app.put_json(url, params=payload, headers={'If-None-Match': '*'}, status=412)
data = json.loads(resp.content)
data = json.loads(resp.text)
assert resp.json['error'] == 'concurrent-access'
# try to create by sending list of eatgs
@ -226,13 +228,13 @@ def test_caching(app, partner_southpark, cut_kevin_uuid, acl):
]
etags.append(cache)
resp = app.put_json(url, params=payload, headers={'If-None-Match': ','.join(etags)}, status=412)
data = json.loads(resp.content)
data = json.loads(resp.text)
assert resp.json['error'] == 'concurrent-access'
# update from the library service
app.authorization = ('Basic', ('cityhall', 'cityhall'))
resp = app.get(url, status=200)
data = json.loads(resp.content)
data = json.loads(resp.text)
data['favourites'].append({
"name": "best books",
"url": "https://southpark.com/library",
@ -254,7 +256,7 @@ def test_caching(app, partner_southpark, cut_kevin_uuid, acl):
assert resp.json['error'] == 'concurrent-access'
resp = app.get(url, status=200)
data = json.loads(resp.content)
data = json.loads(resp.text)
data['favourites'].append(new_item)
etag = resp.headers['Etag']
resp = app.put_json(url, params=payload, headers={'If-Match': etag}, status=200)
@ -412,7 +414,7 @@ def test_cut_uuid_idp_checking(mocked_post, settings, app, acl):
def test_storage_error(app, partner_southpark, cut_kevin_uuid, acl, caplog):
app.authorization = ('Basic', ('library', 'library'))
payload = json.loads(get_tests_file_content('books.json'))
payload = json.loads(force_text(get_tests_file_content('books.json')))
url = '/api/southpark/%s/loans/' % cut_kevin_uuid
app.put_json(url, params=payload, headers={'If-None-Match': '*'}, status=201)
@ -433,7 +435,7 @@ def test_concurrent_put(app, transactional_db):
app.authorization = ('Basic', ('library', 'library'))
payload = json.loads(get_tests_file_content('books.json'))
payload = json.loads(force_text(get_tests_file_content('books.json')))
url = '/api/%s/%s/loans/' % (southpark.name, uuid)
pool_count = 40