tests: update lingo tests to load json from textual response (#35425)

This commit is contained in:
Frédéric Péters 2019-08-18 13:46:34 +02:00
parent fb96c6d4f3
commit e5281adb2b
1 changed files with 26 additions and 26 deletions

View File

@ -117,11 +117,11 @@ def test_default_regie():
def test_regie_api(app):
resp = app.get(reverse('api-regies'))
assert len(json.loads(resp.content).get('data')) == 0
assert len(json.loads(resp.text).get('data')) == 0
test_default_regie()
resp = app.get(reverse('api-regies'))
assert len(json.loads(resp.content).get('data')) == 2
assert json.loads(resp.content).get('data')[0]['id'] == Regie.objects.get(is_default=True).slug
assert len(json.loads(resp.text).get('data')) == 2
assert json.loads(resp.text).get('data')[0]['id'] == Regie.objects.get(is_default=True).slug
def test_payment_min_amount(app, basket_page, regie, user):
items = {'item1': {'amount': '1.5', 'source_url': '/item/1'},
@ -216,7 +216,7 @@ def test_add_amount_to_basket(app, key, regie, user):
url = sign_url(url, key)
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=amount).exists()
assert BasketItem.objects.filter(amount=amount)[0].regie_id == regie.id
@ -227,7 +227,7 @@ def test_add_amount_to_basket(app, key, regie, user):
url = sign_url(url, key)
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=Decimal('64.22')).exists()
data['amount'] = [amount]
@ -236,7 +236,7 @@ def test_add_amount_to_basket(app, key, regie, user):
url = sign_url(url, key)
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=Decimal('81.22')).exists()
# accept french notation if settings.LANGUAGE_CODE is 'fr-*'
@ -261,7 +261,7 @@ def test_add_amount_to_basket(app, key, regie, user):
with override_settings(LANGUAGE_CODE='fr-be'):
resp = app.post_json(url, params=data, status=200)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=Decimal('11.11')).exists()
other_regie.is_default = True
@ -273,7 +273,7 @@ def test_add_amount_to_basket(app, key, regie, user):
resp = app.post_json(url, params=data)
item = BasketItem.objects.get(amount=Decimal('22.23'))
assert resp.status_code == 200
response = json.loads(resp.content)
response = json.loads(resp.text)
assert response['result'] == 'success'
assert response['payment_url'].endswith('/lingo/item/%s/pay' % item.id)
assert BasketItem.objects.filter(amount=Decimal('22.23')).exists()
@ -285,7 +285,7 @@ def test_add_amount_to_basket(app, key, regie, user):
url = sign_url(url, settings.LINGO_API_SIGN_KEY)
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=Decimal('22.24')).exists()
assert BasketItem.objects.filter(amount=Decimal('22.24'))[0].regie_id == regie.id
assert BasketItem.objects.filter(amount=Decimal('22.24'))[0].request_data == data['extra']
@ -296,7 +296,7 @@ def test_add_amount_to_basket(app, key, regie, user):
url = sign_url(url, settings.LINGO_API_SIGN_KEY)
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=Decimal('13.67')).exists()
assert BasketItem.objects.filter(amount=Decimal('13.67'))[0].regie_id == regie.id
@ -463,17 +463,17 @@ def test_cancel_basket_item(app, key, regie, user):
'http://example.com/', 'notify': 'true'}
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
basket_item_id = json.loads(resp.content)['id']
basket_item_id = json.loads(resp.text)['id']
data = {'amount': 21, 'display_name': 'test amount', 'url': 'http://example.net/'}
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
assert BasketItem.objects.filter(amount=21, cancellation_date__isnull=True).exists()
basket_item_id_2 = json.loads(resp.content)['id']
basket_item_id_2 = json.loads(resp.text)['id']
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
url = '%s?email=%s&orig=wcs' % (reverse('api-remove-basket-item'), user_email)
@ -505,9 +505,9 @@ def test_cancel_basket_item_from_cell(app, key, regie, user):
data = {'amount': 42, 'display_name': 'test amount', 'url': 'http://example.org/testitem/'}
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
basket_item_id = json.loads(resp.content)['id']
basket_item_id = json.loads(resp.text)['id']
# check while not logged in
resp = app.get(reverse('lingo-cancel-item', kwargs={'pk': basket_item_id}), status=404)
@ -528,9 +528,9 @@ def test_cancel_basket_item_from_cell(app, key, regie, user):
data = {'amount': 21, 'display_name': 'test amount',
'url': 'http://example.org/testitem/'}
resp = app.post_json(url, params=data)
basket_item2_id = json.loads(resp.content)['id']
basket_item2_id = json.loads(resp.text)['id']
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=21, cancellation_date__isnull=True).exists()
resp = app.get(reverse('lingo-cancel-item', kwargs={'pk': basket_item2_id}))
@ -546,8 +546,8 @@ def test_cancel_basket_item_from_cell(app, key, regie, user):
data = {'amount': 42, 'display_name': 'test amount', 'url': 'http://example.org/testitem/'}
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
basket_item_id = json.loads(resp.content)['id']
assert json.loads(resp.text)['result'] == 'success'
basket_item_id = json.loads(resp.text)['id']
app.get(reverse('lingo-cancel-item', kwargs={'pk': basket_item_id}), status=404)
app.post(reverse('lingo-cancel-item', kwargs={'pk': basket_item_id}), status=403)
@ -778,7 +778,7 @@ def test_transaction_validate(app, key, regie, user):
url = reverse('api-validate-transaction') + '?amount=10&transaction_id=%s&orig=wcs' % t1.id
url = sign_url(url, key)
resp = app.post_json(url, params={})
assert json.loads(resp.content)['err'] == 0
assert json.loads(resp.text)['err'] == 0
operations = TransactionOperation.objects.filter(transaction=t1)
assert len(operations) == 1
assert operations[0].amount == 10
@ -788,7 +788,7 @@ def test_transaction_validate(app, key, regie, user):
url = reverse('api-validate-transaction') + '?amount=10&transaction_id=%s&orig=wcs' % t1.id
url = sign_url(url, key)
resp = app.post_json(url, params={})
assert json.loads(resp.content)['err'] == 1
assert json.loads(resp.text)['err'] == 1
assert TransactionOperation.objects.filter(transaction=t1).count() == 1
def test_transaction_cancel(app, key, regie, user):
@ -806,7 +806,7 @@ def test_transaction_cancel(app, key, regie, user):
url = reverse('api-cancel-transaction') + '?amount=10&transaction_id=%s&orig=wcs' % t1.id
url = sign_url(url, key)
resp = app.post_json(url, params={})
assert json.loads(resp.content)['err'] == 0
assert json.loads(resp.text)['err'] == 0
operations = TransactionOperation.objects.filter(transaction=t1)
assert len(operations) == 1
assert operations[0].amount == 10
@ -816,7 +816,7 @@ def test_transaction_cancel(app, key, regie, user):
url = reverse('api-cancel-transaction') + '?amount=10&transaction_id=%s&orig=wcs' % t1.id
url = sign_url(url, key)
resp = app.post_json(url, params={})
assert json.loads(resp.content)['err'] == 1
assert json.loads(resp.text)['err'] == 1
assert TransactionOperation.objects.filter(transaction=t1).count() == 1
def test_extra_fees(app, basket_page, key, regie, user):
@ -835,7 +835,7 @@ def test_extra_fees(app, basket_page, key, regie, user):
url = sign_url('%s?email=%s&orig=wcs' % (reverse('api-add-basket-item'), user_email), key)
resp = app.post_json(url, params=data)
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert BasketItem.objects.filter(amount=amount).exists()
assert BasketItem.objects.filter(amount=amount)[0].regie_id == regie.id
assert BasketItem.objects.filter(amount=5, extra_fee=True).exists()
@ -853,7 +853,7 @@ def test_extra_fees(app, basket_page, key, regie, user):
assert len(json.loads(request.call_args[1]['data'])['data']) == 2
assert resp.status_code == 200
assert json.loads(resp.content)['result'] == 'success'
assert json.loads(resp.text)['result'] == 'success'
assert not BasketItem.objects.filter(amount=5, extra_fee=True).exists()
assert BasketItem.objects.filter(amount=7, extra_fee=True).exists()