Projet

Général

Profil

0001-lingo-handle-exceptions-raised-by-backend.request-40.patch

Valentin Deniaud, 03 mars 2020 14:35

Télécharger (3,19 ko)

Voir les différences:

Subject: [PATCH] lingo: handle exceptions raised by backend.request (#40244)

 combo/apps/lingo/views.py   |  7 ++++++-
 debian/control              |  2 +-
 setup.py                    |  2 +-
 tests/test_lingo_payment.py | 12 ++++++++++++
 4 files changed, 20 insertions(+), 3 deletions(-)
combo/apps/lingo/views.py
397 397
                kwargs['capture_date'] = capture_date
398 398
        if regie.transaction_options:
399 399
            kwargs.update(regie.transaction_options)
400
        (order_id, kind, data) = payment.request(total_amount, **kwargs)
401 400
        logger = logging.getLogger(__name__)
401
        try:
402
            (order_id, kind, data) = payment.request(total_amount, **kwargs)
403
        except eopayment.PaymentException as e:
404
            logger.error('failed to initiate payment request: %s', e)
405
            messages.error(request, _('Failed to initiate payment request'))
406
            return HttpResponseRedirect(get_payment_status_view(next_url=next_url))
402 407
        logger.info(u'emitted payment request with id %s', smart_text(order_id), extra={
403 408
            'eopayment_order_id': smart_text(order_id), 'eopayment_data': repr(data)})
404 409
        transaction.order_id = order_id
debian/control
20 20
    python3-xstatic-leaflet-markercluster,
21 21
    python3-xstatic-opensans,
22 22
    python3-xstatic-roboto-fontface (>= 0.5.0.0),
23
    python3-eopayment (>= 1.35),
23
    python3-eopayment (>= 1.43),
24 24
    python3-django-ratelimit,
25 25
    python3-sorl-thumbnail,
26 26
    python3-pil,
setup.py
160 160
        'XStatic_JosefinSans',
161 161
        'XStatic_OpenSans',
162 162
        'XStatic_roboto-fontface>=0.5.0.0',
163
        'eopayment>=1.41',
163
        'eopayment>=1.43',
164 164
        'python-dateutil',
165 165
        'djangorestframework>=3.3, <3.7',
166 166
        'django-ratelimit<3',
tests/test_lingo_payment.py
1269 1269
        'error': False,
1270 1270
        'error_msg': ''
1271 1271
    }
1272

  
1273

  
1274
def test_request_payment_exception(app, basket_page, regie, user):
1275
    item = BasketItem.objects.create(user=user, regie=regie,
1276
                        subject='test_item', amount='10.5',
1277
                        source_url='http://example.org/testitem/')
1278

  
1279
    with mock.patch('eopayment.dummy.Payment.request', autospec=True) as mock_request:
1280
        mock_request.side_effect = eopayment.PaymentException
1281
        resp = login(app).get(basket_page.get_online_url())
1282
        resp = resp.form.submit().follow()
1283
        assert 'Failed to initiate payment request' in resp.text
1272
-