11from datetime import date
2- from allocation import views
2+ import pytest
3+ import redis
4+ from allocation import config , views
35from allocation .domain import commands
46from allocation .service_layer import messagebus , unit_of_work
57
68today = date .today ()
79
810
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+
923def test_allocations_view (sqlite_session_factory ):
1024 uow = unit_of_work .SqlAlchemyUnitOfWork (sqlite_session_factory )
1125 messagebus .handle (commands .CreateBatch ("sku1batch" , "sku1" , 50 , None ), uow )
@@ -17,7 +31,7 @@ def test_allocations_view(sqlite_session_factory):
1731 messagebus .handle (commands .Allocate ("otherorder" , "sku1" , 30 ), uow )
1832 messagebus .handle (commands .Allocate ("otherorder" , "sku2" , 10 ), uow )
1933
20- assert views .allocations ("order1" , uow ) == [
34+ assert views .allocations ("order1" ) == [
2135 {"sku" : "sku1" , "batchref" : "sku1batch" },
2236 {"sku" : "sku2" , "batchref" : "sku2batch" },
2337 ]
@@ -30,6 +44,6 @@ def test_deallocation(sqlite_session_factory):
3044 messagebus .handle (commands .Allocate ("o1" , "sku1" , 40 ), uow )
3145 messagebus .handle (commands .ChangeBatchQuantity ("b1" , 10 ), uow )
3246
33- assert views .allocations ("o1" , uow ) == [
47+ assert views .allocations ("o1" ) == [
3448 {"sku" : "sku1" , "batchref" : "b2" },
3549 ]
0 commit comments