The before code tests services separately without checking their interaction. The after code adds a coordination test that simulates placing an order and processing payment together, verifying the flow between services works as expected.
### Before: No coordination test, services tested in isolation
class OrderService:
def place_order(self, order):
# process order
return True
class PaymentService:
def process_payment(self, payment):
# process payment
return True
# No test to check if order and payment coordinate
### After: Coordination test simulating interaction
class OrderService:
def place_order(self, order):
# process order
return True
class PaymentService:
def process_payment(self, payment):
# process payment
return True
class DeliverySystemTest:
def test_order_to_payment_flow(self):
order_service = OrderService()
payment_service = PaymentService()
order_result = order_service.place_order({'id': 1, 'item': 'book'})
assert order_result is True
payment_result = payment_service.process_payment({'order_id': 1, 'amount': 10})
assert payment_result is True
# Verify coordination logic
assert order_result and payment_result
if __name__ == '__main__':
test = DeliverySystemTest()
test.test_order_to_payment_flow()
print('Coordination test passed')