Projet

Général

Profil

0001-tests-lingo-verify-error-message-on-bad-returns-2577.patch

Thomas Noël, 22 août 2018 23:18

Télécharger (3,45 ko)

Voir les différences:

Subject: [PATCH] tests/lingo: verify error message on bad returns (#25772)

 tests/test_lingo_payment.py | 38 +++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)
tests/test_lingo_payment.py
1
from contextlib import contextmanager
1 2
import eopayment
2 3
import pytest
3 4
from datetime import datetime, timedelta
......
27 28
pytestmark = pytest.mark.django_db
28 29

  
29 30

  
31
@contextmanager
32
def check_log(caplog, message):
33
    idx = len(caplog.records)
34
    yield
35
    assert any(message in record.message for record in caplog.records[idx:]), \
36
        '%r not found in log records' % message
37

  
38

  
30 39
@pytest.fixture
31 40
def regie():
32 41
    try:
......
487 496
    assert BasketItem.objects.get(id=item.id).payment_date
488 497
    assert BasketItem.get_items_to_be_paid(user).count() == 0
489 498

  
490
def test_payment_no_callback_just_return(app, basket_page, regie, user):
499
def test_payment_no_callback_just_return(caplog, app, basket_page, regie, user):
491 500
    item = BasketItem.objects.create(user=user, regie=regie,
492 501
                        subject='test_item', amount='10.5',
493 502
                        source_url='http://example.org/testitem/')
......
503 512
    assert data['amount'] == '10.50'
504 513

  
505 514
    # call return with unsigned POST
506
    return_url = reverse('lingo-return', kwargs={'regie_pk': regie.id})
507
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
508
        get_resp = app.post(return_url, params=data)
509
        assert request.call_count == 0
510
    assert get_resp.status_code == 302
511
    assert urlparse.urlparse(get_resp['location']).path == '/test_basket_cell/'
512
    assert Transaction.objects.get(order_id=transaction_id).status == 0  # not paid
515
    with check_log(caplog, 'received unsigned payment'):
516
        return_url = reverse('lingo-return', kwargs={'regie_pk': regie.id})
517
        with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
518
            get_resp = app.post(return_url, params=data)
519
            assert request.call_count == 0
520
        assert get_resp.status_code == 302
521
        assert urlparse.urlparse(get_resp['location']).path == '/test_basket_cell/'
522
        assert Transaction.objects.get(order_id=transaction_id).status == 0  # not paid
523

  
524
    # call return with missing data
525
    with check_log(caplog, 'failed to process payment response: missing transaction_id'):
526
        baddata = data.copy()
527
        del baddata['transaction_id']
528
        with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
529
            get_resp = app.post(return_url, params=baddata)
530
        assert get_resp.status_code == 302
531
        resp = app.get(get_resp['Location'])
532
        assert 'Your payment has been succesfully registered.' not in resp.text
533
        assert 'the payment service failed to provide a correct answer.' in resp.text
534
        assert Transaction.objects.get(order_id=transaction_id).status == 0  # not paid
513 535

  
514 536
    # call return with signed POST
515 537
    data['signed'] = True
516
-