예제 #1
0
def test_charge(mock_charge_create, stripe_payment, gateway_params,
                stripe_charge_success_response):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN,
                                              TRANSACTION_AMOUNT)
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    response = charge(payment_info, gateway_params)

    assert not response.error
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.CHARGE
    assert response.is_success
    assert isclose(response.amount, TRANSACTION_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == stripe_charge_success_response
예제 #2
0
def test_charge(mock_charge_create, stripe_payment, gateway_params,
                stripe_charge_success_response):
    payment = stripe_payment
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    txn, error = charge(payment, FAKE_TOKEN, TRANSACTION_AMOUNT,
                        **gateway_params)

    assert not error
    assert txn.payment == payment
    assert txn.token == TRANSACTION_TOKEN
    assert txn.kind == TransactionKind.CHARGE
    assert txn.is_success
    assert isclose(txn.amount, TRANSACTION_AMOUNT)
    assert txn.currency == TRANSACTION_CURRENCY
    assert txn.gateway_response == response
예제 #3
0
def test_charge_error_response(mock_charge_create, stripe_payment,
                               gateway_params):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN,
                                              TRANSACTION_AMOUNT)
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_charge_create.side_effect = stripe_error

    response = charge(payment_info, gateway_params)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == FAKE_TOKEN
    assert response.kind == TransactionKind.CHARGE
    assert not response.is_success
    assert response.amount == payment.total
    assert response.currency == payment.currency
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
예제 #4
0
def test_charge_error_response(mock_charge_create, stripe_payment,
                               gateway_params):
    payment = stripe_payment
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_charge_create.side_effect = stripe_error

    txn, error = charge(payment, FAKE_TOKEN, TRANSACTION_AMOUNT,
                        **gateway_params)

    assert error == ERROR_MESSAGE
    assert txn.payment == payment
    assert txn.token == ''
    assert txn.kind == TransactionKind.CHARGE
    assert not txn.is_success
    assert txn.amount == payment.total
    assert txn.currency == payment.currency
    assert txn.gateway_response == _get_error_response_from_exc(stripe_error)
예제 #5
0
def test_charge(
        mock_charge_create,
        stripe_payment,
        gateway_params,
        stripe_charge_success_response):
    payment = stripe_payment
    payment_info = create_payment_information(
        payment, FAKE_TOKEN, TRANSACTION_AMOUNT)
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    response = charge(payment_info, gateway_params)

    assert not response['error']
    assert response['transaction_id'] == TRANSACTION_TOKEN
    assert response['kind'] == TransactionKind.CHARGE
    assert response['is_success']
    assert isclose(response['amount'], TRANSACTION_AMOUNT)
    assert response['currency'] == TRANSACTION_CURRENCY
    assert response['raw_response'] == stripe_charge_success_response
예제 #6
0
def test_charge_error_response(
        mock_charge_create,
        stripe_payment,
        gateway_params):
    payment = stripe_payment
    payment_info = create_payment_information(
        payment, FAKE_TOKEN, TRANSACTION_AMOUNT)
    stripe_error = stripe.error.InvalidRequestError(
        message=ERROR_MESSAGE, param=None)
    mock_charge_create.side_effect = stripe_error

    response = charge(payment_info, gateway_params)

    assert response['error'] == ERROR_MESSAGE
    assert response['transaction_id'] == FAKE_TOKEN
    assert response['kind'] == TransactionKind.CHARGE
    assert not response['is_success']
    assert response['amount'] == payment.total
    assert response['currency'] == payment.currency
    assert response['raw_response'] == _get_error_response_from_exc(
        stripe_error)