tests: use response.text for textual contents (py3)

This commit is contained in:
Frédéric Péters 2018-07-25 21:27:32 +02:00
parent 851e032040
commit a50bbad34b
1 changed files with 10 additions and 10 deletions

View File

@ -706,7 +706,7 @@ def test_menu_json(app, admin_user):
resp = app.get('/manage/menu.json?callback=fooBar')
assert resp.headers['content-type'] == 'application/javascript'
assert resp.content.startswith('fooBar([{"')
assert resp.text.startswith('fooBar([{"')
def test_page_multiple_link_cells(app, admin_user):
Page.objects.all().delete()
@ -817,14 +817,14 @@ def test_page_versionning(app, admin_user):
assert resp.text.index('reordered cells') < resp.text.index('changed cell') < resp.text.index('changed title')
resp2 = resp.click('view', index=1)
assert resp2.body.index('Hello world') < resp2.body.index('Foobar3')
assert resp2.text.index('Hello world') < resp2.text.index('Foobar3')
resp2 = resp.click('view', index=0)
assert resp2.body.index('Hello world') > resp2.body.index('Foobar3')
assert resp2.text.index('Hello world') > resp2.text.index('Foobar3')
resp2 = resp.click('view', index=2)
assert 'Foobar1' in resp2.body
assert not 'Hello world' in resp2.body
assert 'Foobar1' in resp2.text
assert not 'Hello world' in resp2.text
assert Page.objects.all().count() == 1
@ -847,23 +847,23 @@ def test_page_versionning(app, admin_user):
assert 'added cell' in resp.text
resp2 = resp.click('view', index=1)
json_cell_url = re.findall(r'/ajax/cell/.*/data_jsoncell-.*/', resp2.body)[0]
json_cell_url = re.findall(r'/ajax/cell/.*/data_jsoncell-.*/', resp2.text)[0]
with mock.patch('combo.utils.requests.get') as requests_get:
data = {'data': [{'url': 'xxx', 'text': 'xxx'}]}
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
resp3 = app.get(json_cell_url)
assert resp3.body.strip() == 'CxxxD'
assert resp3.text.strip() == 'CxxxD'
# previous version should return AxxxB
resp2 = resp.click('view', index=2)
json_cell_url = re.findall(r'/ajax/cell/.*/data_jsoncell-.*/', resp2.body)[0]
json_cell_url = re.findall(r'/ajax/cell/.*/data_jsoncell-.*/', resp2.text)[0]
with mock.patch('combo.utils.requests.get') as requests_get:
data = {'data': [{'url': 'xxx', 'text': 'xxx'}]}
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
resp3 = app.get(json_cell_url)
assert resp3.body.strip() == 'AxxxB'
assert resp3.text.strip() == 'AxxxB'
# check anonymous users can't get to cells from snapshots
app.get('/logout/')
@ -876,7 +876,7 @@ def test_page_versionning(app, admin_user):
resp = resp.follow()
resp2 = resp.click('see online')
assert resp2.body.index('Foobar1') < resp2.body.index('Foobar2') < resp2.body.index('Foobar3')
assert resp2.text.index('Foobar1') < resp2.text.index('Foobar2') < resp2.text.index('Foobar3')
# clean it up
Page.snapshots.all().delete()