Skip to content

Commit 08ed126

Browse files
committed
views tests change to use bus
1 parent 01aeefa commit 08ed126

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

‎tests/integration/test_views.py‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1+
# pylint: disable=redefined-outer-name
12
from datetime import date
3+
from unittest import mock
4+
import pytest
25
from allocation import views
36
from allocation.domain import commands
47
from allocation.service_layer import messagebus, unit_of_work
58

69

7-
def test_allocations_view(sqlite_session_factory):
10+
@pytest.fixture
11+
def sqlite_bus(sqlite_session_factory):
812
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+
bus = messagebus.MessageBus(
14+
uow=uow,
15+
send_mail=mock.Mock(),
16+
publish=mock.Mock(),
17+
)
18+
uow.bus = bus
19+
return bus
20+
21+
22+
def test_allocations_view(sqlite_bus):
23+
sqlite_bus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None))
24+
sqlite_bus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, date.today()))
25+
sqlite_bus.handle(commands.Allocate('order1', 'sku1', 20))
26+
sqlite_bus.handle(commands.Allocate('order1', 'sku2', 20))
1327
# 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)
28+
sqlite_bus.handle(commands.CreateBatch('sku1batch-later', 'sku1', 50, date.today()))
29+
sqlite_bus.handle(commands.Allocate('otherorder', 'sku1', 30))
30+
sqlite_bus.handle(commands.Allocate('otherorder', 'sku2', 10))
1731

18-
assert views.allocations('order1', uow) == [
32+
assert views.allocations('order1', sqlite_bus.uow) == [
1933
{'sku': 'sku1', 'batchref': 'sku1batch'},
2034
{'sku': 'sku2', 'batchref': 'sku2batch'},
2135
]
2236

2337

24-
def test_deallocation(sqlite_session_factory):
25-
uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
26-
messagebus.handle(commands.CreateBatch('b1', 'sku1', 50, None), uow)
27-
messagebus.handle(commands.CreateBatch('b2', 'sku1', 50, date.today()), uow)
28-
messagebus.handle(commands.Allocate('o1', 'sku1', 40), uow)
29-
messagebus.handle(commands.ChangeBatchQuantity('b1', 10), uow)
38+
def test_deallocation(sqlite_bus):
39+
sqlite_bus.handle(commands.CreateBatch('b1', 'sku1', 50, None))
40+
sqlite_bus.handle(commands.CreateBatch('b2', 'sku1', 50, date.today()))
41+
sqlite_bus.handle(commands.Allocate('o1', 'sku1', 40))
42+
sqlite_bus.handle(commands.ChangeBatchQuantity('b1', 10))
3043

31-
assert views.allocations('o1', uow) == [
44+
assert views.allocations('o1', sqlite_bus.uow) == [
3245
{'sku': 'sku1', 'batchref': 'b2'},
3346
]

0 commit comments

Comments
 (0)