コード例 #1
0
def test_authorize_incorrect_token(mock_gateway, payment_dummy,
                                   braintree_not_found_error, gateway_config):
    payment = payment_dummy
    payment_token = 'payment-token'
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    payment_info = create_payment_information(payment, payment_token)
    with pytest.raises(BraintreeException) as e:
        authorize(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
コード例 #2
0
def test_authorize_incorrect_token(
        mock_gateway, payment_dummy, braintree_not_found_error,
        gateway_config):
    payment = payment_dummy
    payment_token = 'payment-token'
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    payment_info = create_payment_information(payment, payment_token)
    with pytest.raises(BraintreeException) as e:
        authorize(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
コード例 #3
0
ファイル: test_braintree.py プロジェクト: smile830/Python
def test_authorize(mock_gateway, payment_dummy, braintree_success_response):
    payment = payment_dummy
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    txn, error = authorize(payment, 'authentication-token')
    assert not error

    assert txn.payment == payment
    assert txn.kind == TransactionKind.AUTH
    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

    mock_response.assert_called_once_with({
        'amount': str(payment.total),
        'payment_method_nonce': 'authentication-token',
        'options': {
            'submit_for_settlement': CONFIRM_MANUALLY,
            'three_d_secure': {
                'required': THREE_D_SECURE_REQUIRED
            }
        },
        **get_customer_data(payment)
    })
コード例 #4
0
def test_authorize(mock_gateway, payment_dummy, braintree_success_response,
                   gateway_config):
    payment = payment_dummy
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

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

    assert response['kind'] == TransactionKind.AUTH
    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(payment.total),
        'payment_method_nonce': 'auth-token',
        'options': {
            'submit_for_settlement': CONFIRM_MANUALLY,
            'three_d_secure': {
                'required': THREE_D_SECURE_REQUIRED
            }
        },
        **get_customer_data(payment_info)
    })
コード例 #5
0
def test_authorize(
        mock_gateway, payment_dummy, braintree_success_response,
        gateway_config):
    payment = payment_dummy
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

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

    assert response['kind'] == TransactionKind.AUTH
    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(payment.total),
        'payment_method_nonce': 'auth-token',
        'options': {
            'submit_for_settlement': CONFIRM_MANUALLY,
            'three_d_secure': {
                'required': THREE_D_SECURE_REQUIRED}},
        **get_customer_data(payment_info)})
コード例 #6
0
def test_authorize(mock_gateway, payment_dummy, braintree_success_response,
                   gateway_config):
    payment = payment_dummy
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    payment_info = create_payment_information(payment, "auth-token")
    response = authorize(payment_info, gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.AUTH
    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(payment.total),
        "payment_method_nonce": "auth-token",
        "options": {
            "submit_for_settlement": CONFIRM_MANUALLY,
            "three_d_secure": {
                "required": THREE_D_SECURE_REQUIRED
            },
        },
        **get_customer_data(payment_info),
    })
コード例 #7
0
ファイル: test_braintree.py プロジェクト: mirumee/saleor
def test_authorize(
    mock_gateway, payment_dummy, braintree_success_response, gateway_config
):
    payment = payment_dummy
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    payment_info = create_payment_information(payment, "auth-token")
    response = authorize(payment_info, gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.AUTH
    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(payment.total),
            "payment_method_nonce": "auth-token",
            "options": {
                "submit_for_settlement": CONFIRM_MANUALLY,
                "three_d_secure": {"required": THREE_D_SECURE_REQUIRED},
            },
            **get_customer_data(payment_info),
        }
    )
コード例 #8
0
def test_authorize_with_customer_id(payment_dummy, sandbox_braintree_gateway_config):
    CUSTOMER_ID = "810066863"  # retrieved from sandbox
    payment = payment_dummy

    payment_info = create_payment_information(payment, None)
    payment_info.amount = 100.00
    payment_info.customer_id = CUSTOMER_ID

    response = authorize(payment_info, sandbox_braintree_gateway_config)
    assert not response.error
    assert response.customer_id == CUSTOMER_ID
    assert response.is_success
コード例 #9
0
def test_authorize_and_save_customer_id(payment_dummy,
                                        sandbox_braintree_gateway_config):
    CUSTOMER_ID = "595109854"  # retrieved from sandbox
    payment = payment_dummy

    payment_info = create_payment_information(payment, "fake-valid-nonce")
    payment_info.amount = 100.00
    payment_info.reuse_source = True

    sandbox_braintree_gateway_config.store_customer = True
    response = authorize(payment_info, sandbox_braintree_gateway_config)
    assert not response.error
    assert response.customer_id == CUSTOMER_ID
コード例 #10
0
def test_authorize_one_time(payment_dummy, sandbox_braintree_gateway_config,
                            braintree_success_response):
    payment = payment_dummy

    payment_info = create_payment_information(payment, "fake-valid-nonce")
    sandbox_braintree_gateway_config.auto_capture = False

    response = authorize(payment_info, sandbox_braintree_gateway_config)
    assert not response.error
    assert response.kind == TransactionKind.AUTH
    assert response.amount == braintree_success_response.transaction.amount
    assert response.currency == braintree_success_response.transaction.currency_iso_code
    assert response.is_success is True
コード例 #11
0
ファイル: test_braintree.py プロジェクト: smile830/Python
def test_authorize_incorrect_token(mock_gateway, mock_transaction,
                                   payment_dummy, braintree_not_found_error):
    payment = payment_dummy
    payment_token = 'payment-token'
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))
    expected_result = ('txn', 'error')
    mock_transaction.return_value = expected_result
    result = authorize(payment, payment_token)
    assert result == expected_result
    mock_transaction.assert_called_once_with(payment,
                                             kind=TransactionKind.AUTH,
                                             token=payment_token)
コード例 #12
0
def test_authorize_error_response(
        mock_gateway, payment_dummy, braintree_error_response, gateway_config):
    payment = payment_dummy
    payment_token = 'payment-token'
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    payment_info = create_payment_information(payment, payment_token)
    response = authorize(payment_info, gateway_config)

    assert response['raw_response'] == extract_gateway_response(braintree_error_response)
    assert not response['is_success']
    assert response['error'] == DEFAULT_ERROR
コード例 #13
0
def test_authorize_error_response(mock_gateway, payment_dummy,
                                  braintree_error_response, gateway_config):
    payment = payment_dummy
    payment_token = "payment-token"
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))

    payment_info = create_payment_information(payment, payment_token)
    response = authorize(payment_info, gateway_config)

    assert response.raw_response == extract_gateway_response(
        braintree_error_response)
    assert not response.is_success
    assert response.error == DEFAULT_ERROR
コード例 #14
0
ファイル: test_braintree.py プロジェクト: smile830/Python
def test_authorize_error_response(mock_gateway, payment_dummy,
                                  braintree_error_response):
    payment = payment_dummy
    payment_token = 'payment-token'
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(sale=mock_response))
    txn, error = authorize(payment, payment_token)

    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