Пример #1
0
def test_void_incorrect_token(payment_txn_preauth, sandbox_braintree_gateway_config):
    payment = payment_txn_preauth

    payment_info = create_payment_information(payment, "incorrect_token")
    with pytest.raises(BraintreeException) as e:
        void(payment_info, sandbox_braintree_gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
Пример #2
0
def test_void_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(void=mock_response))

    payment_info = create_payment_information(payment)
    with pytest.raises(BraintreeException) as e:
        void(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
Пример #3
0
def test_void_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(void=mock_response))

    payment_info = create_payment_information(payment)
    with pytest.raises(BraintreeException) as e:
        void(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
Пример #4
0
def test_void(payment_txn_preauth, sandbox_braintree_gateway_config):
    payment = payment_txn_preauth
    payment_info = create_payment_information(payment, "narvpy2m")
    response = void(payment_info, sandbox_braintree_gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.VOID
    assert response.is_success is True
Пример #5
0
def test_void_error_response(mock_gateway, payment_txn_preauth,
                             braintree_error_response):
    payment = payment_txn_preauth
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(void=mock_response))
    txn, error = void(payment)

    assert txn.gateway_response == extract_gateway_response(
        braintree_error_response)
    assert not txn.is_success
    assert txn.amount == payment.total
    assert txn.currency == payment.currency
    assert error == DEFAULT_ERROR
Пример #6
0
def test_void_incorrect_token(mock_gateway, mock_transaction,
                              payment_txn_preauth, braintree_not_found_error):
    payment = payment_txn_preauth
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(void=mock_response))
    expected_result = ('txn', 'error')
    mock_transaction.return_value = expected_result
    result = void(payment)
    assert result == expected_result
    auth_txn = payment.transactions.filter(kind=TransactionKind.AUTH).first()
    mock_transaction.assert_called_once_with(payment,
                                             kind=TransactionKind.VOID,
                                             token=auth_txn.token)
Пример #7
0
def test_void_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(void=mock_response))

    payment_info = create_payment_information(payment)
    response = void(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_void_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(void=mock_response))

    payment_info = create_payment_information(payment)
    response = void(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_void(mock_gateway, payment_txn_preauth, braintree_success_response,
              gateway_config):
    payment = payment_txn_preauth
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(void=mock_response))

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

    assert response.kind == TransactionKind.VOID
    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(transaction_id=payment_info.token)
Пример #10
0
def test_void(
        mock_gateway, payment_txn_preauth, braintree_success_response,
        gateway_config):
    payment = payment_txn_preauth
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(void=mock_response))

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

    assert response['kind'] == TransactionKind.VOID
    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(transaction_id=payment_info['token'])
Пример #11
0
def test_void(mock_gateway, payment_txn_preauth, braintree_success_response):
    payment = payment_txn_preauth
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(void=mock_response))
    txn, error = void(payment)
    assert not error

    assert txn.payment == payment
    assert txn.kind == TransactionKind.VOID
    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(transaction_id=auth_txn.token)