Example #1
0
def test_gateway_void_failed(
        mock_get_payment_gateway, payment_txn_preauth, gateway_params):
    txn = payment_txn_preauth.transactions.first()
    txn.is_success = False
    payment = payment_txn_preauth

    mock_void = Mock(return_value=(txn, EXAMPLE_ERROR))
    mock_get_payment_gateway.return_value = (Mock(void=mock_void), gateway_params)
    with pytest.raises(PaymentError) as exc:
        gateway_void(payment)
    assert exc.value.message == EXAMPLE_ERROR

    payment.refresh_from_db()
    assert payment.is_active
Example #2
0
def test_gateway_void(mock_get_payment_gateway, payment_txn_preauth, gateway_params):
    txn = payment_txn_preauth.transactions.first()
    payment = payment_txn_preauth
    assert payment.is_active

    mock_void = Mock(return_value=(txn, ''))
    mock_get_payment_gateway.return_value = (Mock(void=mock_void), gateway_params)

    gateway_void(payment)
    mock_get_payment_gateway.assert_called_once_with(payment.gateway)
    mock_void.assert_called_once_with(payment=payment, **gateway_params)

    payment.refresh_from_db()
    assert payment.is_active == False
Example #3
0
def test_void_gateway_error(payment_txn_preauth, monkeypatch):
    monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)
    with pytest.raises(PaymentError):
        txn = gateway_void(payment=payment_txn_preauth)
        assert txn.kind == TransactionKind.VOID
        assert not txn.is_success
        assert txn.payment == payment_txn_preauth
Example #4
0
def test_void_gateway_error(payment_txn_preauth, monkeypatch):
    monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)
    with pytest.raises(PaymentError):
        txn = gateway_void(payment=payment_txn_preauth)
        assert txn.kind == TransactionKind.VOID
        assert not txn.is_success
        assert txn.payment == payment_txn_preauth
Example #5
0
def test_void_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_void(payment=payment)
        assert txn is None
Example #6
0
def test_void_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_void(payment=payment)
        assert txn is None
Example #7
0
def test_gateway_void_failed(mock_get_payment_gateway, payment_txn_preauth,
                             gateway_config, dummy_response):
    txn = payment_txn_preauth.transactions.first()
    txn.is_success = False
    payment = payment_txn_preauth

    dummy_response.kind = TransactionKind.VOID
    dummy_response.is_success = False
    mock_void = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (Mock(void=mock_void),
                                             gateway_config)
    with pytest.raises(PaymentError) as exc:
        gateway_void(payment)
    assert exc.value.message == EXAMPLE_ERROR

    payment.refresh_from_db()
    assert payment.is_active
Example #8
0
def test_gateway_void_failed(
    mock_get_payment_gateway, payment_txn_preauth, gateway_config, dummy_response
):
    txn = payment_txn_preauth.transactions.first()
    txn.is_success = False
    payment = payment_txn_preauth

    dummy_response.kind = TransactionKind.VOID
    dummy_response.is_success = False
    mock_void = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (Mock(void=mock_void), gateway_config)
    with pytest.raises(PaymentError) as exc:
        gateway_void(payment)
    assert exc.value.message == EXAMPLE_ERROR

    payment.refresh_from_db()
    assert payment.is_active
Example #9
0
def test_void_success(payment_txn_preauth):
    assert payment_txn_preauth.is_active
    assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED
    txn = gateway_void(payment=payment_txn_preauth)
    assert txn.is_success
    assert txn.kind == TransactionKind.VOID
    assert txn.payment == payment_txn_preauth
    payment_txn_preauth.refresh_from_db()
    assert not payment_txn_preauth.is_active
    assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED
Example #10
0
def test_void_success(payment_txn_preauth):
    assert payment_txn_preauth.is_active
    assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED
    txn = gateway_void(payment=payment_txn_preauth)
    assert txn.is_success
    assert txn.kind == TransactionKind.VOID
    assert txn.payment == payment_txn_preauth
    payment_txn_preauth.refresh_from_db()
    assert not payment_txn_preauth.is_active
    assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED
Example #11
0
def test_gateway_void(mock_get_payment_gateway, payment_txn_preauth,
                      gateway_params, dummy_response):
    txn = payment_txn_preauth.transactions.first()
    payment = payment_txn_preauth
    assert payment.is_active

    dummy_response.kind = TransactionKind.VOID
    mock_void = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (Mock(void=mock_void),
                                             gateway_params)

    payment_info = create_payment_information(payment, txn.token)
    gateway_void(payment)

    mock_get_payment_gateway.assert_called_once_with(payment.gateway)
    mock_void.assert_called_once_with(payment_information=payment_info,
                                      connection_params=gateway_params)

    payment.refresh_from_db()
    assert payment.is_active is False
Example #12
0
def test_gateway_void(
        mock_get_payment_gateway, payment_txn_preauth,
        gateway_params, dummy_response):
    txn = payment_txn_preauth.transactions.first()
    payment = payment_txn_preauth
    assert payment.is_active

    dummy_response['kind'] = TransactionKind.VOID
    mock_void = Mock(return_value=dummy_response)
    mock_get_payment_gateway.return_value = (Mock(void=mock_void), gateway_params)

    payment_info = create_payment_information(payment, txn.token)
    gateway_void(payment)

    mock_get_payment_gateway.assert_called_once_with(payment.gateway)
    mock_void.assert_called_once_with(
        payment_information=payment_info, connection_params=gateway_params)

    payment.refresh_from_db()
    assert payment.is_active == False
Example #13
0
def test_gateway_void_errors(payment_dummy):
    payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
    with pytest.raises(PaymentError) as exc:
        gateway_void(payment_dummy)
    exc.value.message == "Only pre-authorized transactions can be voided."
Example #14
0
def test_gateway_void_errors(payment_dummy):
    payment_dummy.charge_status = ChargeStatus.FULLY_CHARGED
    with pytest.raises(PaymentError) as exc:
        gateway_void(payment_dummy)
    assert exc.value.message == "Only pre-authorized transactions can be voided."