1
1
from datetime import date
2
- from allocation import views
2
+ import pytest
3
+ import redis
4
+ from allocation import config , views
3
5
from allocation .domain import commands
4
6
from allocation .service_layer import messagebus , unit_of_work
5
7
6
8
today = date .today ()
7
9
8
10
11
+ @pytest .fixture
12
+ def cleanup_redis ():
13
+ r = redis .Redis (** config .get_redis_host_and_port ())
14
+ yield
15
+ for k in r .keys ():
16
+ print ("cleaning up redis key" , k )
17
+ r .delete (k )
18
+
19
+
20
+ pytestmark = pytest .mark .usefixtures ("cleanup_redis" )
21
+
22
+
9
23
def test_allocations_view (sqlite_session_factory ):
10
24
uow = unit_of_work .SqlAlchemyUnitOfWork (sqlite_session_factory )
11
25
messagebus .handle (commands .CreateBatch ("sku1batch" , "sku1" , 50 , None ), uow )
@@ -17,7 +31,7 @@ def test_allocations_view(sqlite_session_factory):
17
31
messagebus .handle (commands .Allocate ("otherorder" , "sku1" , 30 ), uow )
18
32
messagebus .handle (commands .Allocate ("otherorder" , "sku2" , 10 ), uow )
19
33
20
- assert views .allocations ("order1" , uow ) == [
34
+ assert views .allocations ("order1" ) == [
21
35
{"sku" : "sku1" , "batchref" : "sku1batch" },
22
36
{"sku" : "sku2" , "batchref" : "sku2batch" },
23
37
]
@@ -30,6 +44,6 @@ def test_deallocation(sqlite_session_factory):
30
44
messagebus .handle (commands .Allocate ("o1" , "sku1" , 40 ), uow )
31
45
messagebus .handle (commands .ChangeBatchQuantity ("b1" , 10 ), uow )
32
46
33
- assert views .allocations ("o1" , uow ) == [
47
+ assert views .allocations ("o1" ) == [
34
48
{"sku" : "sku1" , "batchref" : "b2" },
35
49
]
0 commit comments