def test_charge_invalid_request(mocked_gateway, mocked_logger, razorpay_payment, gateway_params): # Data to be passed payment_token = '123' # Assign the side effect to the gateway's `charge()` method, # that should trigger the expected error. mocked_gateway.return_value.payment.capture.side_effect = BadRequestError() payment_info = create_payment_information(razorpay_payment, payment_token=payment_token, amount=TRANSACTION_AMOUNT) # Attempt charging response = charge(payment_info, gateway_params) # Ensure an error was returned assert response.error == errors.INVALID_REQUEST assert not response.is_success # Ensure the response is correctly set assert response.kind == TransactionKind.CHARGE assert response.transaction_id == payment_token # Ensure the HTTP error was logged assert mocked_logger.call_count == 1
def test_charge_invalid_request(mocked_gateway, mocked_logger, razorpay_payment, gateway_params): # Data to be passed payment_token = '123' # Assign the side effect to the gateway's `charge()` method, # that should trigger the expected error. mocked_gateway.return_value.payment.capture.side_effect = BadRequestError() # Attempt charging txn, error = charge(razorpay_payment, payment_token, TRANSACTION_AMOUNT, **gateway_params) # Ensure an error was returned assert error == errors.INVALID_REQUEST assert not txn.is_success # Ensure the transaction is correctly set assert txn.payment == razorpay_payment assert txn.kind == TransactionKind.CHARGE assert txn.token == payment_token # Ensure the HTTP error was logged assert mocked_logger.call_count == 1
def test_charge(mocked_gateway, razorpay_payment, razorpay_success_response, gateway_params): # Data to be passed payment_token = '123' # Mock the gateway response to a success response mocked_gateway.return_value.payment.capture.return_value = ( razorpay_success_response) payment_info = create_payment_information(razorpay_payment, payment_token=payment_token, amount=TRANSACTION_AMOUNT) # Attempt charging response = charge(payment_info, gateway_params) # Ensure the was no error returned assert not response.error assert response.is_success assert response.kind == TransactionKind.CHARGE assert response.amount == TRANSACTION_AMOUNT assert response.currency == razorpay_success_response['currency'] assert response.raw_response == razorpay_success_response assert response.transaction_id == razorpay_success_response['id']
def test_charge_invalid_request( mocked_gateway, mocked_logger, razorpay_payment, gateway_params): # Data to be passed payment_token = '123' # Assign the side effect to the gateway's `charge()` method, # that should trigger the expected error. mocked_gateway.return_value.payment.capture.side_effect = BadRequestError() payment_info = create_payment_information( razorpay_payment, payment_token=payment_token, amount=TRANSACTION_AMOUNT) # Attempt charging response = charge(payment_info, gateway_params) # Ensure an error was returned assert response['error'] == errors.INVALID_REQUEST assert not response['is_success'] # Ensure the response is correctly set assert response['kind'] == TransactionKind.CHARGE assert response['transaction_id'] == payment_token # Ensure the HTTP error was logged assert mocked_logger.call_count == 1
def test_charge( mocked_gateway, razorpay_payment, razorpay_success_response, gateway_params): # Data to be passed payment_token = '123' # Mock the gateway response to a success response mocked_gateway.return_value.payment.capture.return_value = ( razorpay_success_response) payment_info = create_payment_information( razorpay_payment, payment_token=payment_token, amount=TRANSACTION_AMOUNT) # Attempt charging response = charge(payment_info, gateway_params) # Ensure the was no error returned assert not response['error'] assert response['is_success'] assert response['kind'] == TransactionKind.CHARGE assert response['amount'] == TRANSACTION_AMOUNT assert response['currency'] == razorpay_success_response['currency'] assert response['raw_response'] == razorpay_success_response assert response['transaction_id'] == razorpay_success_response['id']
def test_charge_unsupported_currency(razorpay_payment, gateway_params): # Set the payment currency to an unsupported currency razorpay_payment.currency = 'USD' # Data to be passed payment_token = '123' # Attempt charging txn, error = charge(razorpay_payment, payment_token, TRANSACTION_AMOUNT, **gateway_params) # Ensure a error was returned assert error == errors.UNSUPPORTED_CURRENCY % {'currency': 'USD'} assert not txn.is_success # Ensure the transaction is correctly set assert txn.payment == razorpay_payment assert txn.kind == TransactionKind.CHARGE assert txn.token == payment_token
def test_charge_unsupported_currency(razorpay_payment, gateway_params): # Set the payment currency to an unsupported currency razorpay_payment.currency = 'USD' # Data to be passed payment_token = '123' payment_info = create_payment_information( razorpay_payment, payment_token=payment_token, amount=TRANSACTION_AMOUNT) # Attempt charging response = charge(payment_info, gateway_params) # Ensure a error was returned assert response['error'] == ( errors.UNSUPPORTED_CURRENCY % {'currency': 'USD'}) assert not response['is_success'] # Ensure the response is correctly set assert response['kind'] == TransactionKind.CHARGE assert response['transaction_id'] == payment_token
def test_charge_unsupported_currency(razorpay_payment, gateway_params): # Set the payment currency to an unsupported currency razorpay_payment.currency = "USD" # Data to be passed payment_token = "123" payment_info = create_payment_information(razorpay_payment, payment_token=payment_token, amount=TRANSACTION_AMOUNT) # Attempt charging response = charge(payment_info, gateway_params) # Ensure a error was returned assert response.error == (errors.UNSUPPORTED_CURRENCY % { "currency": "USD" }) assert not response.is_success # Ensure the response is correctly set assert response.kind == TransactionKind.CHARGE assert response.transaction_id == payment_token
def test_charge(mocked_gateway, razorpay_payment, razorpay_success_response, gateway_params): # Data to be passed payment_token = '123' # Mock the gateway response to a success response mocked_gateway.return_value.payment.capture.return_value = ( razorpay_success_response) # Attempt charging txn, error = charge(razorpay_payment, payment_token, TRANSACTION_AMOUNT, **gateway_params) # Ensure the was no error returned assert not error assert txn.is_success assert txn.payment == razorpay_payment assert txn.kind == TransactionKind.CHARGE assert txn.amount == TRANSACTION_AMOUNT assert txn.currency == razorpay_success_response['currency'] assert txn.gateway_response == {} assert txn.token == razorpay_success_response['id']