def post(self): request_arguments = request_parser.parse_args() transaction_flow = OnlineTransaction( request_arguments.CreditCardNumber, request_arguments.CardHolder, request_arguments.ExpirationDate, request_arguments.Amount, security_code=request_arguments.SecurityCode) result = transaction_flow.make_transaction() self.status_code = result['status_code'] self.response_data = result['data'] return self.send_response()
def test_premium_payment_gateway_using_function_calling( self, make_transaction, app_): """ Test premium payment gateway called with their own class make_transaction function """ with app_.test_request_context( ): # this is for current_app.debug used at make_request for debugging purpose transaction_flow = OnlineTransaction( '5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 521, # premium amount security_code=321) transaction_flow.make_transaction() make_transaction.assert_called_once()
def test_premium_payment_gateway(self, app_): """ Test premium payment gateway response. """ with app_.test_request_context( ): # this is for current_app.debug used at make_request for debugging purpose transaction_flow = OnlineTransaction( '5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 521, # premium amount security_code=321) result = transaction_flow.make_transaction() assert result['status_code'] == 200 assert result['data'] == 'ok'
def test_premium_payment_gateway_retries(self, make_request, app_): """ Test premium payment gateway with retries """ with app_.test_request_context( ): # this is for current_app.debug used at make_request for debugging purpose transaction_flow = OnlineTransaction( '5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 521, # premium amount security_code=321) transaction_flow.make_transaction() # second call with transaction call contains retries args, kwargs = make_request.call_args_list[1] assert kwargs['retries'] == 3
def test_expensive_payment_failure(self, make_transaction, make_request, app_): """ Test expensive payment gateway failure with cheap payment gateway first side effect will throw failure that expensive_payment is unavailable and move to cheap payment gateway """ with app_.test_request_context( ): # this is for current_app.debug used at make_request for debugging purpose transaction_flow = OnlineTransaction( '5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 450, # expensive amount security_code=321) result = transaction_flow.make_transaction() make_transaction.assert_called_once() assert result['status_code'] == 200 assert result['data'] == 'ok'
async def payment_process_api(payment_details: PaymentRequest, response: Response): transaction_flow = OnlineTransaction( payment_details.CreditCardNumber, payment_details.CardHolder, payment_details.ExpirationDate, payment_details.Amount, security_code=payment_details.SecurityCode ) result = await transaction_flow.make_transaction() response.status_code = result['status_code'] return result['data']
async def test_cheap_payment_gateway_using_function_calling( self, make_transaction): """ Test cheap payment gateway called with their own class make_transaction function """ transaction_flow = OnlineTransaction('5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 12, security_code=321) await transaction_flow.make_transaction() make_transaction.assert_called_once()
async def test_cheap_payment_gateway(self): """ Test cheap payment gateway response. """ transaction_flow = OnlineTransaction('5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 12, security_code=321) result = await transaction_flow.make_transaction() assert result['status_code'] == 200 assert result['data'] == 'ok'
async def test_premium_payment_gateway_retries(self, make_request): """ Test premium payment gateway with retries """ transaction_flow = OnlineTransaction( '5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 521, # premium amount security_code=321) await transaction_flow.make_transaction() # second call with transaction call contains retries args, kwargs = make_request.call_args_list[1] assert kwargs['retries'] == 3
async def test_expensive_payment_failure(self, make_transaction, make_request): """ Test expensive payment gateway failure with cheap payment gateway first side effect will throw failure that expensive_payment is unavailable and move to cheap payment gateway """ transaction_flow = OnlineTransaction( '5555555555554444', 'syed hassan raza', datetime.datetime(2021, 12, 12), 450, # expensive amount security_code=321) result = await transaction_flow.make_transaction() make_transaction.assert_called_once() assert result['status_code'] == 200 assert result['data'] == 'ok'