Пример #1
0
def test_gateway_authorize(mock_get_payment_gateway, payment_txn_preauth,
                           gateway_params, transaction_token):
    payment_token = transaction_token
    txn = payment_txn_preauth.transactions.first()
    payment = payment_txn_preauth

    mock_authorize = Mock(return_value=(txn, ''))
    mock_get_payment_gateway.return_value = (Mock(authorize=mock_authorize),
                                             gateway_params)

    gateway_authorize(payment, payment_token)
    mock_get_payment_gateway.assert_called_once_with(payment.gateway)
    mock_authorize.assert_called_once_with(payment, payment_token,
                                           **gateway_params)
Пример #2
0
def test_gateway_authorize_failed(
        mock_get_payment_gateway, payment_txn_preauth, gateway_params,
        transaction_token):
    payment_token = transaction_token
    txn = payment_txn_preauth.transactions.first()
    txn.is_success = False
    payment = payment_txn_preauth

    mock_authorize = Mock(return_value=(txn, EXAMPLE_ERROR))
    mock_get_payment_gateway.return_value = (
        Mock(authorize=mock_authorize), gateway_params)
    with pytest.raises(PaymentError) as exc:
        gateway_authorize(payment, payment_token)
    assert exc.value.message == EXAMPLE_ERROR
Пример #3
0
def test_gateway_authorize(mock_get_payment_gateway, payment_txn_preauth,
                           gateway_params, transaction_token, dummy_response):
    payment = payment_txn_preauth
    payment_token = transaction_token

    mock_authorize = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (Mock(authorize=mock_authorize),
                                             gateway_params)

    payment_info = create_payment_information(payment, payment_token)
    gateway_authorize(payment, payment_token)

    mock_get_payment_gateway.assert_called_once_with(payment.gateway)
    mock_authorize.assert_called_once_with(payment_information=payment_info,
                                           connection_params=gateway_params)
Пример #4
0
def test_authorize_success(payment_dummy):
    txn = gateway_authorize(payment=payment_dummy, payment_token='Fake')
    assert txn.is_success
    assert txn.kind == TransactionKind.AUTH
    assert txn.payment == payment_dummy
    payment_dummy.refresh_from_db()
    assert payment_dummy.is_active
Пример #5
0
def test_authorize_success(payment_dummy):
    txn = gateway_authorize(payment=payment_dummy, payment_token='Fake')
    assert txn.is_success
    assert txn.kind == TransactionKind.AUTH
    assert txn.payment == payment_dummy
    payment_dummy.refresh_from_db()
    assert payment_dummy.is_active
Пример #6
0
def test_gateway_charge_errors(payment_dummy, transaction_token, settings):
    payment = payment_dummy
    gateway_authorize(payment, transaction_token)
    with pytest.raises(PaymentError) as exc:
        gateway_capture(payment, Decimal("0"))
    assert exc.value.message == "Amount should be a positive number."

    payment.charge_status = ChargeStatus.FULLY_REFUNDED
    with pytest.raises(PaymentError) as exc:
        gateway_capture(payment, Decimal("10"))
    assert exc.value.message == "This payment cannot be captured."

    payment.charge_status = ChargeStatus.NOT_CHARGED
    with pytest.raises(PaymentError) as exc:
        gateway_capture(payment, Decimal("1000000"))
    assert exc.value.message == ("Unable to charge more than un-captured amount.")
Пример #7
0
def test_authorize_gateway_error(payment_dummy, monkeypatch):
    monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)
    with pytest.raises(PaymentError):
        txn = gateway_authorize(payment=payment_dummy, payment_token="Fake")
        assert txn.kind == TransactionKind.AUTH
        assert not txn.is_success
        assert txn.payment == payment_dummy
Пример #8
0
def test_authorize_gateway_error(payment_dummy, monkeypatch):
    monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)
    with pytest.raises(PaymentError):
        txn = gateway_authorize(payment=payment_dummy, payment_token="Fake")
        assert txn.kind == TransactionKind.AUTH
        assert not txn.is_success
        assert txn.payment == payment_dummy
Пример #9
0
def test_gateway_charge_errors(payment_dummy, transaction_token, settings):
    payment = payment_dummy
    gateway_authorize(payment, transaction_token)
    with pytest.raises(PaymentError) as exc:
        gateway_capture(payment, Decimal("0"))
    assert exc.value.message == "Amount should be a positive number."

    payment.charge_status = ChargeStatus.FULLY_REFUNDED
    with pytest.raises(PaymentError) as exc:
        gateway_capture(payment, Decimal("10"))
    assert exc.value.message == "This payment cannot be captured."

    payment.charge_status = ChargeStatus.NOT_CHARGED
    with pytest.raises(PaymentError) as exc:
        gateway_capture(payment, Decimal("1000000"))
    assert exc.value.message == ("Unable to charge more than un-captured amount.")
Пример #10
0
def test_gateway_authorize_failed(
        mock_get_payment_gateway, payment_txn_preauth, gateway_params,
        transaction_token, dummy_response):
    payment = payment_txn_preauth
    payment_token = transaction_token
    txn = payment_txn_preauth.transactions.first()
    txn.is_success = False
    payment = payment_txn_preauth

    dummy_response['is_success'] = False
    mock_authorize = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (
        Mock(authorize=mock_authorize), gateway_params)
    with pytest.raises(PaymentError) as exc:
        gateway_authorize(payment, payment_token)
    assert exc.value.message == EXAMPLE_ERROR
Пример #11
0
def test_gateway_authorize(
        mock_get_payment_gateway, payment_txn_preauth, gateway_params,
        transaction_token, dummy_response):
    payment = payment_txn_preauth
    payment_token = transaction_token

    mock_authorize = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (
        Mock(authorize=mock_authorize), gateway_params)

    payment_info = create_payment_information(payment, payment_token)
    gateway_authorize(payment, payment_token)

    mock_get_payment_gateway.assert_called_once_with(payment.gateway)
    mock_authorize.assert_called_once_with(
        payment_information=payment_info, connection_params=gateway_params)
Пример #12
0
def test_authorize_failed(is_active, charge_status, payment_dummy):
    payment = payment_dummy
    payment.is_active = is_active
    payment.charge_status = charge_status
    payment.save()
    with pytest.raises(PaymentError):
        txn = gateway_authorize(payment=payment, payment_token='Fake')
        assert txn is None
Пример #13
0
def test_authorize_failed(is_active, charge_status, payment_dummy):
    payment = payment_dummy
    payment.is_active = is_active
    payment.charge_status = charge_status
    payment.save()
    with pytest.raises(PaymentError):
        txn = gateway_authorize(payment=payment, payment_token='Fake')
        assert txn is None
Пример #14
0
def test_gateway_authorize_failed(
    mock_get_payment_gateway,
    payment_txn_preauth,
    gateway_config,
    transaction_token,
    dummy_response,
):
    payment_token = transaction_token
    txn = payment_txn_preauth.transactions.first()
    txn.is_success = False
    payment = payment_txn_preauth

    dummy_response.is_success = False
    mock_authorize = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (
        Mock(authorize=mock_authorize),
        gateway_config,
    )
    with pytest.raises(PaymentError) as exc:
        gateway_authorize(payment, payment_token)
    assert exc.value.message == EXAMPLE_ERROR
Пример #15
0
def test_gateway_authorize_errors(payment_dummy):
    payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
    with pytest.raises(PaymentError) as exc:
        gateway_authorize(payment_dummy, "payment-token")
    assert exc.value.message == (
        "Charged transactions cannot be authorized again.")
Пример #16
0
def test_gateway_authorize_errors(payment_dummy):
    payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
    with pytest.raises(PaymentError) as exc:
        gateway_authorize(payment_dummy, "payment-token")
    assert exc.value.message == ("Charged transactions cannot be authorized again.")