Skip to content

Commit 58fd37d

Browse files
committed
isolated test for a handler [test_handler_in_isolation]
1 parent f8ed253 commit 58fd37d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/unit/test_handlers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,24 @@ def publish_events(self):
135135
for product in self.products.seen:
136136
while product.events:
137137
self.events_published.append(product.events.pop(0))
138+
139+
140+
def test_reallocates_if_necessary_isolated():
141+
uow = FakeUnitOfWorkWithFakeMessageBus()
142+
143+
# test setup as before
144+
messagebus.handle(events.BatchCreated("batch1", "INDIFFERENT-TABLE", 50, None), uow)
145+
messagebus.handle(events.BatchCreated("batch2", "INDIFFERENT-TABLE", 50, date.today()), uow)
146+
messagebus.handle(events.AllocationRequired("order1", "INDIFFERENT-TABLE", 20), uow)
147+
messagebus.handle(events.AllocationRequired("order2", "INDIFFERENT-TABLE", 20), uow)
148+
[batch1, batch2] = uow.products.get(sku="INDIFFERENT-TABLE").batches
149+
assert batch1.available_quantity == 10
150+
151+
messagebus.handle(events.BatchQuantityChanged("batch1", 25), uow)
152+
153+
# assert on new events emitted rather than downstream side-effects
154+
[reallocation_event] = uow.events_published
155+
assert isinstance(reallocation_event, events.AllocationRequired)
156+
assert reallocation_event.orderid in {'order1', 'order2'}
157+
assert reallocation_event.sku == 'INDIFFERENT-TABLE'
158+

0 commit comments

Comments
 (0)