示例#1
0
def test_capture_incorrect_token(mock_gateway, payment_txn_preauth,
                                 braintree_not_found_error, gateway_config):
    payment = payment_txn_preauth
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(
        submit_for_settlement=mock_response))

    payment_info = create_payment_information(payment)
    with pytest.raises(BraintreeException) as e:
        capture(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
示例#2
0
def test_capture_incorrect_token(
        mock_gateway, payment_txn_preauth, braintree_not_found_error,
        gateway_config):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(
        transaction=Mock(submit_for_settlement=mock_response))

    payment_info = create_payment_information(payment)
    with pytest.raises(BraintreeException) as e:
        capture(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
示例#3
0
def test_capture_incorrect_token(payment_txn_preauth,
                                 sandbox_braintree_gateway_config):
    payment_info = create_payment_information(payment_txn_preauth, "12345")
    with pytest.raises(BraintreeException) as e:
        response = capture(payment_info, sandbox_braintree_gateway_config)
        assert str(e.value) == DEFAULT_ERROR_MESSAGE
        assert response.raw_response == extract_gateway_response(
            braintree_error_response)
        assert not response.is_success
        assert response.error == DEFAULT_ERROR
示例#4
0
def test_capture(payment_txn_preauth, sandbox_braintree_gateway_config):
    payment = payment_txn_preauth
    amount = Decimal("80.00")

    payment_info = create_payment_information(payment, "m30bcfym", amount)
    response = capture(payment_info, sandbox_braintree_gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.CAPTURE
    assert response.amount == amount
    assert response.currency == "EUR"
    assert response.is_success is True
示例#5
0
def test_capture_error_response(mock_gateway, payment_txn_preauth,
                                braintree_error_response, gateway_config):
    payment = payment_txn_preauth
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(
        submit_for_settlement=mock_response))

    payment_info = create_payment_information(payment, 'token')
    response = capture(payment_info, gateway_config)

    assert response.raw_response == extract_gateway_response(
        braintree_error_response)
    assert not response.is_success
    assert response.error == DEFAULT_ERROR
示例#6
0
def test_capture_error_response(mock_gateway, payment_txn_preauth,
                                braintree_error_response):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(
        submit_for_settlement=mock_response))
    txn, error = capture(payment, amount)

    assert txn.gateway_response == extract_gateway_response(
        braintree_error_response)
    assert not txn.is_success
    assert txn.amount == amount
    assert txn.currency == payment.currency
    assert error == DEFAULT_ERROR
示例#7
0
def test_capture_error_response(
    mock_gateway, payment_txn_preauth, braintree_error_response, gateway_config
):
    payment = payment_txn_preauth
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(
        transaction=Mock(submit_for_settlement=mock_response)
    )

    payment_info = create_payment_information(payment, "token")
    response = capture(payment_info, gateway_config)

    assert response.raw_response == extract_gateway_response(braintree_error_response)
    assert not response.is_success
    assert response.error == DEFAULT_ERROR
示例#8
0
def test_capture_error_response(
        mock_gateway, payment_txn_preauth, braintree_error_response,
        gateway_config):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(
        transaction=Mock(submit_for_settlement=mock_response))

    payment_info = create_payment_information(payment, 'token')
    response = capture(payment_info, gateway_config)

    assert response['raw_response'] == extract_gateway_response(
        braintree_error_response)
    assert not response['is_success']
    assert response['error'] == DEFAULT_ERROR
示例#9
0
def test_capture_incorrect_token(mock_gateway, mock_transaction,
                                 payment_txn_preauth,
                                 braintree_not_found_error):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(
        submit_for_settlement=mock_response))
    expected_result = ('txn', 'error')
    mock_transaction.return_value = expected_result
    result = capture(payment, amount)
    assert result == expected_result
    auth_txn = payment.transactions.filter(kind=TransactionKind.AUTH).first()
    mock_transaction.assert_called_once_with(payment,
                                             kind=TransactionKind.CAPTURE,
                                             token=auth_txn.token,
                                             amount=amount)
示例#10
0
def test_capture(mock_gateway, payment_txn_preauth, braintree_success_response,
                 gateway_config):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(
        submit_for_settlement=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    response = capture(payment_info, gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.CAPTURE
    assert response.amount == braintree_success_response.transaction.amount
    assert response.currency == braintree_success_response.transaction.currency_iso_code
    assert response.transaction_id == braintree_success_response.transaction.id
    assert response.is_success == braintree_success_response.is_success

    mock_response.assert_called_once_with(amount=str(amount),
                                          transaction_id=payment_info.token)
示例#11
0
def test_capture(
        mock_gateway, payment_txn_preauth, braintree_success_response,
        settings, gateway_config):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(
        transaction=Mock(submit_for_settlement=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    response = capture(payment_info, gateway_config)
    assert not response['error']

    assert response['kind'] == TransactionKind.CAPTURE
    assert response['amount'] == braintree_success_response.transaction.amount
    assert response['currency'] == braintree_success_response.transaction.currency_iso_code
    assert response['transaction_id'] == braintree_success_response.transaction.id
    assert response['is_success'] == braintree_success_response.is_success

    mock_response.assert_called_once_with(
        amount=str(amount), transaction_id=payment_info['token'])
示例#12
0
def test_capture(mock_gateway, payment_txn_preauth, braintree_success_response,
                 settings):
    payment = payment_txn_preauth
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(
        submit_for_settlement=mock_response))
    txn, error = capture(payment, amount)
    assert not error

    assert txn.payment == payment
    assert txn.kind == TransactionKind.CAPTURE
    assert txn.amount == braintree_success_response.transaction.amount
    assert txn.currency == braintree_success_response.transaction.currency_iso_code
    assert txn.gateway_response == success_gateway_response(
        braintree_success_response)
    assert txn.token == braintree_success_response.transaction.id
    assert txn.is_success == braintree_success_response.is_success

    auth_txn = payment.transactions.filter(kind=TransactionKind.AUTH).first()
    mock_response.assert_called_once_with(amount=str(amount),
                                          transaction_id=auth_txn.token)
示例#13
0
def test_capture(
    mock_gateway, payment_txn_preauth, braintree_success_response, gateway_config
):
    payment = payment_txn_preauth
    amount = Decimal("10.00")
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(
        transaction=Mock(submit_for_settlement=mock_response)
    )

    payment_info = create_payment_information(payment, "token", amount)
    response = capture(payment_info, gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.CAPTURE
    assert response.amount == braintree_success_response.transaction.amount
    assert response.currency == braintree_success_response.transaction.currency_iso_code
    assert response.transaction_id == braintree_success_response.transaction.id
    assert response.is_success == braintree_success_response.is_success

    mock_response.assert_called_once_with(
        amount=str(amount), transaction_id=payment_info.token
    )