def test_cheappaymentgateway1(self): """ Probability of Success is 1, now no matter what it will not fail. (Same thing goes for availbility) """ PaymentGateway.set_probability_of_success(1) msg = process_request(10) self.assertEqual(msg, "10 Transaction Successfully via CheapPaymentGateway")
def get(self): """ This is the method for processing the payment in REST api . this executes when the client hits the get request :return: response to the client """ args = video_put_args.parse_args() # all the args passed in the request is validated # any failure will send a response of 400 BAD REQUEST validate_request(args) try: # This is the main method which process the request and select the appropriate gateway msg = process_request(args["Amount"]) return jsonify({"message": msg}) except Exception as e: abort(500, message=f"Unknowm Error Occured: {e}")
def test_premiumpaymentgateway2(self): PaymentGateway.set_probability_of_success(0) msg = process_request(2500) self.assertEqual(msg, "2500 Transaction Failed via PremiumPaymentGateway")
def test_expensivepaymentgateway2(self): PaymentGateway.set_probability_of_avail(0) PaymentGateway.set_probability_of_success(1) msg = process_request(25) self.assertEqual(msg, "25 Transaction Successfully via CheapPaymentGateway")
def test_cheappaymentgateway2(self): PaymentGateway.set_probability_of_success(0) msg = process_request(5) self.assertEqual(msg, "5 Transaction Failed via CheapPaymentGateway")