|
1 | 1 | from datetime import date |
2 | 2 | from unittest import mock |
3 | | -from typing import List |
4 | 3 | import pytest |
5 | 4 | from allocation import events, exceptions, messagebus, repository, unit_of_work |
6 | 5 |
|
@@ -123,36 +122,3 @@ def test_reallocates_if_necessary(): |
123 | 122 | assert batch1.available_quantity == 5 |
124 | 123 | # and 20 will be reallocated to the next batch |
125 | 124 | assert batch2.available_quantity == 30 |
126 | | - |
127 | | - |
128 | | -class FakeUnitOfWorkWithFakeMessageBus(FakeUnitOfWork): |
129 | | - |
130 | | - def __init__(self): |
131 | | - super().__init__() |
132 | | - self.events_published = [] # type: List[events.Event] |
133 | | - |
134 | | - def publish_events(self): |
135 | | - for product in self.products.seen: |
136 | | - while product.events: |
137 | | - 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