Projet

Général

Profil

0002-lingo-pass-extra-item-info-to-eopayment-backend-4299.patch

Valentin Deniaud, 08 juin 2020 12:26

Télécharger (4,5 ko)

Voir les différences:

Subject: [PATCH 2/2] lingo: pass extra item info to eopayment backend (#42992)

 combo/apps/lingo/views.py   | 10 +++++++
 tests/test_lingo_payment.py | 57 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 1 deletion(-)
combo/apps/lingo/views.py
402 402
        kwargs = {
403 403
            'email': email, 'first_name': firstname, 'last_name': lastname
404 404
        }
405
        kwargs['merchant_name'] = settings.TEMPLATE_VARS.get('global_title') or 'Compte Citoyen'
406
        kwargs['items_info'] = []
407
        for item in remote_items or items:
408
            kwargs['items_info'].append({
409
                'text': item.subject,
410
                'amount': item.amount,
411
                'reference_id': item.reference_id,
412
            })
413
            if not email and item.email:
414
                kwargs['email'] = item.email
405 415
        if items:
406 416
            capture_date = items[0].capture_date
407 417
            if capture_date:
tests/test_lingo_payment.py
387 387
    location = urlparse.urlparse(resp.location)
388 388
    assert location.path == '/'
389 389
    assert location.hostname == 'dummy-payment.demo.entrouvert.com'
390

  
391
    items_info = [{'text': 'test item', 'amount': Decimal('10.00'), 'reference_id': ''}]
390 392
    eopayment_mock.assert_called_once_with(
391 393
        Decimal(10), email=user.email, first_name=user.first_name, last_name=user.last_name,
392
        capture_date=capture_date)
394
        capture_date=capture_date, merchant_name='Compte Citoyen', items_info=items_info
395
    )
396

  
397

  
398
def test_basket_items_extra_info(app, user, regie, basket_page, monkeypatch):
399
    User.objects.get_or_create(email=user.email)
400
    url = '%s?email=%s' % (reverse('api-add-basket-item'), user.email)
401
    items_info = [{'text': 'face mask', 'amount': Decimal(10), 'reference_id': '1'},
402
                  {'text': 'face mask 2', 'amount': Decimal(15), 'reference_id': '2'}]
403
    items_post_data = [{'display_name': 'face mask', 'amount': 10, 'reference_id': 1},
404
                       {'display_name': 'face mask 2', 'amount': 15, 'reference_id': 2}]
405
    global_title = 'FooBar'
406

  
407
    url = sign_url(url, settings.LINGO_API_SIGN_KEY)
408
    for item in items_post_data:
409
        resp = app.post_json(url, params=item)
410
    assert resp.status_code == 200
411

  
412
    resp = login(app).get('/test_basket_cell/')
413
    import eopayment
414
    eopayment_mock = mock.Mock(
415
        return_value=('orderid', eopayment.URL, 'http://dummy-payment.demo.entrouvert.com/'))
416
    monkeypatch.setattr(eopayment.Payment, 'request', eopayment_mock)
417
    with override_settings(TEMPLATE_VARS={'global_title': global_title}):
418
        resp = resp.form.submit()
419
    eopayment_mock.assert_called_once_with(
420
        Decimal(25), email=user.email, first_name=user.first_name, last_name=user.last_name,
421
        merchant_name=global_title, items_info=items_info
422
    )
423

  
424

  
425
def test_basket_items_extra_info_no_basket(app, regie, basket_page, monkeypatch):
426
    # when no user is authenticated, it is still possible to pass an email to eopayment backend
427
    url = reverse('api-add-basket-item')
428
    email = 'test@entrouvert.com'
429
    items_info = [{'text': 'face mask', 'amount': Decimal(10), 'reference_id': ''}]
430
    item = {'display_name': 'face mask', 'amount': 10, 'email_address': email}
431

  
432
    url = sign_url(url, settings.LINGO_API_SIGN_KEY)
433
    resp = app.post_json(url, params=item)
434
    assert resp.status_code == 200
435
    item = BasketItem.objects.first()
436
    assert item.user is None
437

  
438
    payment_url = resp.json['payment_url']
439
    import eopayment
440
    eopayment_mock = mock.Mock(
441
        return_value=('orderid', eopayment.URL, 'http://dummy-payment.demo.entrouvert.com/'))
442
    monkeypatch.setattr(eopayment.Payment, 'request', eopayment_mock)
443
    resp = app.get(payment_url)
444
    eopayment_mock.assert_called_once_with(
445
        Decimal(10), email=email, first_name='', last_name='', items_info=items_info,
446
        merchant_name='Compte Citoyen'
447
    )
393 448

  
394 449

  
395 450
@pytest.mark.parametrize("invalid_capture_date", [8, '', 'not-a-date'])
396
-