tests/lingo: verify error message on bad returns (#25772)
This commit is contained in:
parent
35ac62ff50
commit
4dcc778492
|
@ -1,3 +1,4 @@
|
|||
from contextlib import contextmanager
|
||||
import eopayment
|
||||
import pytest
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -27,6 +28,14 @@ from .test_manager import login
|
|||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
@contextmanager
|
||||
def check_log(caplog, message):
|
||||
idx = len(caplog.records)
|
||||
yield
|
||||
assert any(message in record.message for record in caplog.records[idx:]), \
|
||||
'%r not found in log records' % message
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def regie():
|
||||
try:
|
||||
|
@ -487,7 +496,7 @@ def test_payment_callback_waiting(app, basket_page, regie, user):
|
|||
assert BasketItem.objects.get(id=item.id).payment_date
|
||||
assert BasketItem.get_items_to_be_paid(user).count() == 0
|
||||
|
||||
def test_payment_no_callback_just_return(app, basket_page, regie, user):
|
||||
def test_payment_no_callback_just_return(caplog, app, basket_page, regie, user):
|
||||
item = BasketItem.objects.create(user=user, regie=regie,
|
||||
subject='test_item', amount='10.5',
|
||||
source_url='http://example.org/testitem/')
|
||||
|
@ -503,13 +512,26 @@ def test_payment_no_callback_just_return(app, basket_page, regie, user):
|
|||
assert data['amount'] == '10.50'
|
||||
|
||||
# call return with unsigned POST
|
||||
return_url = reverse('lingo-return', kwargs={'regie_pk': regie.id})
|
||||
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
|
||||
get_resp = app.post(return_url, params=data)
|
||||
assert request.call_count == 0
|
||||
assert get_resp.status_code == 302
|
||||
assert urlparse.urlparse(get_resp['location']).path == '/test_basket_cell/'
|
||||
assert Transaction.objects.get(order_id=transaction_id).status == 0 # not paid
|
||||
with check_log(caplog, 'received unsigned payment'):
|
||||
return_url = reverse('lingo-return', kwargs={'regie_pk': regie.id})
|
||||
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
|
||||
get_resp = app.post(return_url, params=data)
|
||||
assert request.call_count == 0
|
||||
assert get_resp.status_code == 302
|
||||
assert urlparse.urlparse(get_resp['location']).path == '/test_basket_cell/'
|
||||
assert Transaction.objects.get(order_id=transaction_id).status == 0 # not paid
|
||||
|
||||
# call return with missing data
|
||||
with check_log(caplog, 'failed to process payment response: missing transaction_id'):
|
||||
baddata = data.copy()
|
||||
del baddata['transaction_id']
|
||||
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
|
||||
get_resp = app.post(return_url, params=baddata)
|
||||
assert get_resp.status_code == 302
|
||||
resp = app.get(get_resp['Location'])
|
||||
assert 'Your payment has been succesfully registered.' not in resp.text
|
||||
assert 'the payment service failed to provide a correct answer.' in resp.text
|
||||
assert Transaction.objects.get(order_id=transaction_id).status == 0 # not paid
|
||||
|
||||
# call return with signed POST
|
||||
data['signed'] = True
|
||||
|
|
Loading…
Reference in New Issue