Skip to content

Commit e235b21

Browse files
committed
fix view tests to use bootstrap. [bootstrap_view_tests]
1 parent 8c57cdd commit e235b21

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

tests/integration/test_views.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
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

9+
@pytest.fixture
10+
def sqlite_bus(sqlite_session_factory):
11+
bus = bootstrap.bootstrap(
12+
start_orm=True,
13+
uow=unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory),
14+
send_mail=lambda *args: None,
15+
publish=lambda *args: None,
16+
)
17+
yield bus
18+
clear_mappers()
619

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)
20+
def test_allocations_view(sqlite_bus):
21+
sqlite_bus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None))
22+
sqlite_bus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, date.today()))
23+
sqlite_bus.handle(commands.Allocate('order1', 'sku1', 20))
24+
sqlite_bus.handle(commands.Allocate('order1', 'sku2', 20))
1325
# 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)
26+
sqlite_bus.handle(commands.CreateBatch('sku1batch-later', 'sku1', 50, date.today()))
27+
sqlite_bus.handle(commands.Allocate('otherorder', 'sku1', 30))
28+
sqlite_bus.handle(commands.Allocate('otherorder', 'sku2', 10))
1729

18-
assert views.allocations('order1', uow) == [
30+
assert views.allocations('order1', sqlite_bus.uow) == [
1931
{'sku': 'sku1', 'batchref': 'sku1batch'},
2032
{'sku': 'sku2', 'batchref': 'sku2batch'},
2133
]
2234

2335

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)
36+
def test_deallocation(sqlite_bus):
37+
sqlite_bus.handle(commands.CreateBatch('b1', 'sku1', 50, None))
38+
sqlite_bus.handle(commands.CreateBatch('b2', 'sku1', 50, date.today()))
39+
sqlite_bus.handle(commands.Allocate('o1', 'sku1', 40))
40+
sqlite_bus.handle(commands.ChangeBatchQuantity('b1', 10))
3041

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

0 commit comments

Comments
 (0)