def test_ExpensivePaymentGatewayRetriesOnCheapOne(mocker): amount = 25.23 payment = Payment(creditCardNumber, cardHolder, expirationDate, securityCode, amount) mocked_func = mocker.patch('expensivePaymentGateway.ExpensivePaymentGateway.processPayment') mocked_func2 = mocker.patch('cheapPaymentGateway.CheapPaymentGateway.processPayment') payment.process() mocked_func.assert_called() mocked_func2.assert_called()
def ProcessPayment(): data = request.form creditCardNumber, cardHolder, expirationDate, securityCode, amount = SanitizeParameters( data) try: payment = Payment(creditCardNumber, cardHolder, expirationDate, securityCode, amount) print("uptest") result = payment.process() print("test") if result.status_code == 200: return "Payment is processed : 200 OK", 200 except (TypeError, ValueError) as e: return "The request is invalid: 400 bad request", 400 except: return "500 internal server error", 500 return "500 internal server error", 500
def test_PremiumPaymentGatewayRetriesThreeTimes(mocker): amount = 521.25 payment = Payment(creditCardNumber, cardHolder, expirationDate, securityCode, amount) mocked_func = mocker.patch('premiumPaymentGateway.PremiumPaymentGateway.processPayment') payment.process() assert len(mocked_func.call_args_list) == 4
def test_CorrectGatewayIsUsedForOver500GBP(mocker): amount = 521.25 payment = Payment(creditCardNumber, cardHolder, expirationDate, securityCode, amount) mocked_func = mocker.patch('premiumPaymentGateway.PremiumPaymentGateway.processPayment') payment.process() mocked_func.assert_called()
def test_CorrectGatewayIsUsedFor21_500GBP(mocker): amount = 21.3 payment = Payment(creditCardNumber, cardHolder, expirationDate, securityCode, amount) mocked_func = mocker.patch('expensivePaymentGateway.ExpensivePaymentGateway.processPayment') payment.process() mocked_func.assert_called()
def test_CorrectGatewayIsUsedForLessThan20GBP(mocker): amount = 19.5 payment = Payment(creditCardNumber, cardHolder, expirationDate, securityCode, amount) mocked_func = mocker.patch('cheapPaymentGateway.CheapPaymentGateway.processPayment') payment.process() mocked_func.assert_called()