|
| 1 | +from datetime import date |
| 2 | +from allocation import views |
| 3 | +from allocation.domain import commands |
| 4 | +from allocation.service_layer import messagebus, unit_of_work |
| 5 | + |
| 6 | + |
| 7 | +def test_allocations_view(sqlite_session_factory): |
| 8 | + uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory) |
| 9 | + messagebus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None), uow) |
| 10 | + messagebus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, date.today()), uow) |
| 11 | + messagebus.handle(commands.Allocate('order1', 'sku1', 20), uow) |
| 12 | + messagebus.handle(commands.Allocate('order1', 'sku2', 20), uow) |
| 13 | + # add a spurious batch and order to make sure we're getting the right ones |
| 14 | + messagebus.handle(commands.CreateBatch('sku1batch-later', 'sku1', 50, date.today()), uow) |
| 15 | + messagebus.handle(commands.Allocate('otherorder', 'sku1', 30), uow) |
| 16 | + messagebus.handle(commands.Allocate('otherorder', 'sku2', 10), uow) |
| 17 | + |
| 18 | + assert views.allocations('order1', uow) == [ |
| 19 | + {'sku': 'sku1', 'batchref': 'sku1batch'}, |
| 20 | + {'sku': 'sku2', 'batchref': 'sku2batch'}, |
| 21 | + ] |
0 commit comments