def pay_order(order: Order): if order.total == 0: raise ValueError("Can't pay an order with total 0.") card = input("Please enter your card number: ") month = int(input("Please enter the card expiry month: ")) year = int(input("Please enter the card expiry year: ")) payment_processor = PaymentProcessor( "6cfb67f3-6281-4031-b893-ea85db0dce20") payment_processor.charge(card, month, year, amount=order.total) order.pay()
def test_pay_order_invalid(monkeypatch: MonkeyPatch): with pytest.raises(ValueError): inputs = ["1249190007575069", "12", "2024"] monkeypatch.setattr("builtins.input", lambda _: inputs.pop(0)) monkeypatch.setattr(PaymentProcessor, "_check_api_key", lambda _: True) order = Order() pay_order(order)
def test_pay_order(monkeypatch: MonkeyPatch): inputs = ["1249190007575069", "12", "2024"] monkeypatch.setattr("builtins.input", lambda _: inputs.pop(0)) monkeypatch.setattr(PaymentProcessor, "_check_api_key", lambda _: True) order = Order() order.line_items.append(LineItem(name="Shoes", price=100_00, quantity=2))
def test_order_total() -> None: order = Order() order.line_items.append(LineItem(name="Test", price=100)) assert order.total == 100
def test_empty_order_total() -> None: order = Order() assert order.total == 0
def test_order_pay() -> None: order = Order() order.pay() assert order.status == OrderStatus.PAID
def main(): # Test card number: 1249190007575069 order = Order() order.line_items.append(LineItem(name="Shoes", price=100_00, quantity=2))