def test_get_error_response_from_exc(): stripe_error = stripe.error.StripeError(json_body={"message": ERROR_MESSAGE}) invalid_request_error = stripe.error.InvalidRequestError( message=ERROR_MESSAGE, param=None ) assert _get_error_response_from_exc(stripe_error) == {"message": ERROR_MESSAGE} assert _get_error_response_from_exc(invalid_request_error) == {}
def test_get_error_response_from_exc(): stripe_error = stripe.error.StripeError( json_body={'message': ERROR_MESSAGE}) invalid_request_error = stripe.error.InvalidRequestError( message=ERROR_MESSAGE, param=None) assert _get_error_response_from_exc(stripe_error) == { 'message': ERROR_MESSAGE} assert _get_error_response_from_exc(invalid_request_error) == {}
def test_authorize_error_response(mock_charge_create, stripe_payment, gateway_config): payment = stripe_payment payment_info = create_payment_information(payment, FAKE_TOKEN) stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_create.side_effect = stripe_error response = authorize(payment_info, gateway_config) assert response.error == ERROR_MESSAGE assert response.transaction_id == FAKE_TOKEN assert response.kind == TransactionKind.AUTH 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)
def test_authorize_error_response(mock_charge_create, stripe_payment, gateway_params): payment = stripe_payment payment_info = create_payment_information(payment, FAKE_TOKEN) stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_create.side_effect = stripe_error response = authorize(payment_info, gateway_params) assert response.error == ERROR_MESSAGE assert response.transaction_id == FAKE_TOKEN assert response.kind == TransactionKind.AUTH 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)
def test_capture_error_response(mock_charge_retrieve, stripe_authorized_payment, gateway_params): payment = stripe_authorized_payment stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_retrieve.side_effect = stripe_error txn, error = capture(payment, TRANSACTION_AMOUNT, **gateway_params) assert error == ERROR_MESSAGE assert txn.payment == payment assert txn.token == '' assert txn.kind == TransactionKind.CAPTURE 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)
def test_authorize_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 = authorize(payment, FAKE_TOKEN, **gateway_params) assert error == ERROR_MESSAGE assert txn.payment == payment assert txn.token == '' assert txn.kind == TransactionKind.AUTH 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)
def test_void_error_response(mock_charge_retrieve, mock_refund_create, stripe_authorized_payment, gateway_params): payment = stripe_authorized_payment mock_charge_retrieve.return_value = Mock(id='') stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_refund_create.side_effect = stripe_error txn, error = void(payment, **gateway_params) assert error == ERROR_MESSAGE assert txn.payment == payment assert txn.token == '' assert txn.kind == TransactionKind.VOID assert not txn.is_success assert txn.amount == payment.total assert txn.currency == TRANSACTION_CURRENCY assert txn.gateway_response == _get_error_response_from_exc(stripe_error)
def test_capture_error_response(mock_charge_retrieve, stripe_authorized_payment, gateway_params): payment = stripe_authorized_payment payment_info = create_payment_information(payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT) stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_retrieve.side_effect = stripe_error response = capture(payment_info, gateway_params) assert response.error == ERROR_MESSAGE assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.CAPTURE 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)
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)
def test_capture_error_response( mock_charge_retrieve, stripe_authorized_payment, gateway_config ): payment = stripe_authorized_payment payment_info = create_payment_information( payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT ) stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_retrieve.side_effect = stripe_error response = capture(payment_info, gateway_config) assert response.error == ERROR_MESSAGE assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.CAPTURE 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)
def test_refund_error_response(mock_charge_retrieve, mock_refund_create, stripe_charged_payment, gateway_params): payment = stripe_charged_payment payment_info = create_payment_information(payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT) mock_charge_retrieve.return_value = Mock(id='') stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_refund_create.side_effect = stripe_error response = refund(payment_info, gateway_params) assert response.error == ERROR_MESSAGE assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.REFUND assert not response.is_success assert response.amount == payment.total assert response.currency == TRANSACTION_CURRENCY assert response.raw_response == _get_error_response_from_exc(stripe_error)
def test_refund_error_response( mock_charge_retrieve, mock_refund_create, stripe_captured_payment, gateway_config ): payment = stripe_captured_payment payment_info = create_payment_information( payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT ) mock_charge_retrieve.return_value = Mock(id="") stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_refund_create.side_effect = stripe_error response = refund(payment_info, gateway_config) assert response.error == ERROR_MESSAGE assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.REFUND assert not response.is_success assert response.amount == payment.total assert response.currency == TRANSACTION_CURRENCY assert response.raw_response == _get_error_response_from_exc(stripe_error)
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)