Skip to content

Commit f954dae

Browse files
committed
fix view tests to use bootstrap. [bootstrap_view_tests]
1 parent 6a8afb6 commit f954dae

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

tests/integration/test_views.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1+
# pylint: disable=redefined-outer-name
12
from datetime import date
2-
from allocation import views
3+
from sqlalchemy.orm import clear_mappers
4+
import pytest
5+
from allocation import bootstrap, views
36
from allocation.domain import commands
4-
from allocation.service_layer import messagebus, unit_of_work
7+
from allocation.service_layer import unit_of_work
58

69
today = date.today()
710

811

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)
12+
@pytest.fixture
13+
def sqlite_bus(sqlite_session_factory):
14+
bus = bootstrap.bootstrap(
15+
start_orm=True,
16+
uow=unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory),
17+
send_mail=lambda *args: None,
18+
publish=lambda *args: None,
19+
)
20+
yield bus
21+
clear_mappers()
22+
23+
def test_allocations_view(sqlite_bus):
24+
sqlite_bus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None))
25+
sqlite_bus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, today))
26+
sqlite_bus.handle(commands.Allocate('order1', 'sku1', 20))
27+
sqlite_bus.handle(commands.Allocate('order1', 'sku2', 20))
1528
# 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)
29+
sqlite_bus.handle(commands.CreateBatch('sku1batch-later', 'sku1', 50, today))
30+
sqlite_bus.handle(commands.Allocate('otherorder', 'sku1', 30))
31+
sqlite_bus.handle(commands.Allocate('otherorder', 'sku2', 10))
1932

20-
assert views.allocations('order1', uow) == [
33+
assert views.allocations('order1', sqlite_bus.uow) == [
2134
{'sku': 'sku1', 'batchref': 'sku1batch'},
2235
{'sku': 'sku2', 'batchref': 'sku2batch'},
2336
]
2437

2538

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

33-
assert views.allocations('o1', uow) == [
45+
assert views.allocations('o1', sqlite_bus.uow) == [
3446
{'sku': 'sku1', 'batchref': 'b2'},
3547
]

0 commit comments

Comments
 (0)