tests: check against text version of responses (#35425)

This commit is contained in:
Frédéric Péters 2019-08-18 12:20:48 +02:00
parent cbb1814087
commit f48c661980
5 changed files with 18 additions and 18 deletions

View File

@ -228,7 +228,7 @@ def test_chartng_cell_view(app, normal_user):
cell.chart_type = 'table'
cell.save()
resp = app.get('/')
assert '<td>222</td>' in resp.body
assert '<td>222</td>' in resp.text
def test_chartng_cell_manager(app, admin_user):

View File

@ -22,9 +22,9 @@ def test_adding_gallery_images(app, admin_user):
app.post(reverse('combo-gallery-image-add', kwargs={'gallery_pk': cell.id}), params={'image': ['foo'], 'title': 'white'}, status=403)
app = login(app)
mgr = app.get(reverse('combo-manager-page-edit-cell', kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()}), status=200)
assert '<ul class="gallery"' in mgr.content
assert 'js/combo.gallery.js' in mgr.content
resp = app.get(reverse('combo-manager-page-edit-cell', kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()}), status=200)
assert '<ul class="gallery"' in resp.text
assert 'js/combo.gallery.js' in resp.text
assert len(cell.image_set.all()) == 0
form = app.get(reverse('combo-gallery-image-add', kwargs={'gallery_pk': cell.id})).form
@ -43,11 +43,11 @@ def test_adding_gallery_images(app, admin_user):
form.submit()
assert len(cell.image_set.filter(title='pink')) == 1
data = app.get('/%s/' % page.slug, status=200)
assert 'pink' in data.content
resp = app.get('/%s/' % page.slug, status=200)
assert 'pink' in resp.text
mgr = app.get(reverse('combo-gallery-image-delete', kwargs={'gallery_pk': cell.id, 'pk': image_2.id}), status=302)
resp = app.get(reverse('combo-gallery-image-delete', kwargs={'gallery_pk': cell.id, 'pk': image_2.id}), status=302)
assert len(cell.image_set.all()) == 1
data = app.get('/%s/' % page.slug, status=200)
assert 'pink' not in data.content
resp = app.get('/%s/' % page.slug, status=200)
assert 'pink' not in resp.text

View File

@ -287,8 +287,8 @@ def test_payment_backend_list(app, admin_user):
resp = app.get('/manage/lingo/paymentbackends/', status=200)
assert '/manage/lingo/paymentbackends/add' in resp.text
assert 'label1' in resp.content
assert 'label2' in resp.content
assert 'label1' in resp.text
assert 'label2' in resp.text
for payment_backend in PaymentBackend.objects.all():
assert '/manage/lingo/paymentbackends/%s' % payment_backend.pk in resp.text

View File

@ -243,16 +243,16 @@ def test_add_amount_to_basket(app, key, regie, user):
url = '%s?amount=10,00&email=%s&orig=wcs' % (reverse('api-add-basket-item'), user_email)
url = sign_url(url, key)
resp = app.post_json(url, params=data, status=400)
assert 'invalid value for "amount" in query string' in resp.content
assert 'invalid value for "amount" in query string' in resp.text
data['amount'] = '1,10'
url = '%s?amount=10.00&email=%s&orig=wcs' % (reverse('api-add-basket-item'), user_email)
url = sign_url(url, key)
resp = app.post_json(url, params=data, status=400)
assert 'invalid value for "amount" in payload' in resp.content
assert 'invalid value for "amount" in payload' in resp.text
data['amount'] = '1.10'
data['extra'] = {'amount': '0,01'}
resp = app.post_json(url, params=data, status=400)
assert 'invalid value for "amount" in extra payload' in resp.content
assert 'invalid value for "amount" in extra payload' in resp.text
data['amount'] = '1,10'
data['extra'] = {'amount': '0,01'}
@ -341,7 +341,7 @@ def test_add_basket_capture_date_format(app, user, regie, invalid_capture_date):
data['capture_date'] = invalid_capture_date
url = sign_url(url, settings.LINGO_API_SIGN_KEY)
resp = app.post_json(url, params=data, status=400)
assert 'Bad format for capture date, it should be yyyy-mm-dd.' in resp.content
assert 'Bad format for capture date, it should be yyyy-mm-dd.' in resp.text
def test_cant_pay_if_different_capture_date(app, basket_page, regie, user):
@ -367,7 +367,7 @@ def test_cant_pay_if_different_capture_date(app, basket_page, regie, user):
assert resp.status_code == 302
assert urlparse.urlparse(resp.location).path == '/test_basket_cell/'
resp = resp.follow()
assert "Invalid grouping for basket items: different capture dates." in resp.content
assert "Invalid grouping for basket items: different capture dates." in resp.text
def test_pay_single_basket_item(app, key, regie, user, john_doe):

View File

@ -1159,7 +1159,7 @@ def test_json_cell_syntax_validation(app, admin_user):
resp.forms[0]['cdata_jsoncell-1-template_string'].value = '{% syntax|error %}'
resp.forms[0]['cdata_jsoncell-1-url'].value = 'http://example.com'
resp = resp.forms[0].submit()
assert 'syntax error: Invalid block tag' in resp.body
assert 'syntax error: Invalid block tag' in resp.text
assert JsonCell.objects.count() == 1
assert JsonCell.objects.first().template_string is None
# valid syntax
@ -1167,6 +1167,6 @@ def test_json_cell_syntax_validation(app, admin_user):
resp.forms[0]['cdata_jsoncell-1-template_string'].value = '{{ ok }}'
resp.forms[0]['cdata_jsoncell-1-url'].value = 'http://example.com'
resp = resp.forms[0].submit().follow()
assert 'syntax error' not in resp.body
assert 'syntax error' not in resp.text
assert JsonCell.objects.count() == 1
assert JsonCell.objects.first().template_string == '{{ ok }}'