Skip to content

Commit 2105f0c

Browse files
committed
fix view tests to use bootstrap. [bootstrap_view_tests]
1 parent 2060810 commit 2105f0c

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

tests/integration/test_views.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
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+
24+
def test_allocations_view(sqlite_bus):
25+
sqlite_bus.handle(commands.CreateBatch("sku1batch", "sku1", 50, None))
26+
sqlite_bus.handle(commands.CreateBatch("sku2batch", "sku2", 50, today))
27+
sqlite_bus.handle(commands.Allocate("order1", "sku1", 20))
28+
sqlite_bus.handle(commands.Allocate("order1", "sku2", 20))
1529
# 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)
30+
sqlite_bus.handle(commands.CreateBatch("sku1batch-later", "sku1", 50, today))
31+
sqlite_bus.handle(commands.Allocate("otherorder", "sku1", 30))
32+
sqlite_bus.handle(commands.Allocate("otherorder", "sku2", 10))
1933

20-
assert views.allocations("order1", uow) == [
34+
assert views.allocations("order1", sqlite_bus.uow) == [
2135
{"sku": "sku1", "batchref": "sku1batch"},
2236
{"sku": "sku2", "batchref": "sku2batch"},
2337
]
2438

2539

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)
40+
def test_deallocation(sqlite_bus):
41+
sqlite_bus.handle(commands.CreateBatch("b1", "sku1", 50, None))
42+
sqlite_bus.handle(commands.CreateBatch("b2", "sku1", 50, today))
43+
sqlite_bus.handle(commands.Allocate("o1", "sku1", 40))
44+
sqlite_bus.handle(commands.ChangeBatchQuantity("b1", 10))
3245

33-
assert views.allocations("o1", uow) == [
46+
assert views.allocations("o1", sqlite_bus.uow) == [
3447
{"sku": "sku1", "batchref": "b2"},
3548
]

0 commit comments

Comments
 (0)