Skip to content

Commit bd3501d

Browse files
committed
integration test for our view
1 parent ce6f584 commit bd3501d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/integration/test_views.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
today = date.today()
7+
8+
9+
def test_allocations_view(sqlite_session_factory):
10+
uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
11+
messagebus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None), uow)
12+
messagebus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, today), uow)
13+
messagebus.handle(commands.Allocate('order1', 'sku1', 20), uow)
14+
messagebus.handle(commands.Allocate('order1', 'sku2', 20), uow)
15+
# add a spurious batch and order to make sure we're getting the right ones
16+
messagebus.handle(commands.CreateBatch('sku1batch-later', 'sku1', 50, today), uow)
17+
messagebus.handle(commands.Allocate('otherorder', 'sku1', 30), uow)
18+
messagebus.handle(commands.Allocate('otherorder', 'sku2', 10), uow)
19+
20+
assert views.allocations('order1', uow) == [
21+
{'sku': 'sku1', 'batchref': 'sku1batch'},
22+
{'sku': 'sku2', 'batchref': 'sku2batch'},
23+
]

0 commit comments

Comments
 (0)