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+ pytestmark = pytest .mark .usefixtures ('cleanup_redis' )
20+
21+
922def test_allocations_view (sqlite_session_factory ):
1023 uow = unit_of_work .SqlAlchemyUnitOfWork (sqlite_session_factory )
1124 messagebus .handle (commands .CreateBatch ('sku1batch' , 'sku1' , 50 , None ), uow )
@@ -17,7 +30,7 @@ def test_allocations_view(sqlite_session_factory):
1730 messagebus .handle (commands .Allocate ('otherorder' , 'sku1' , 30 ), uow )
1831 messagebus .handle (commands .Allocate ('otherorder' , 'sku2' , 10 ), uow )
1932
20- assert views .allocations ('order1' , uow ) == [
33+ assert views .allocations ('order1' ) == [
2134 {'sku' : 'sku1' , 'batchref' : 'sku1batch' },
2235 {'sku' : 'sku2' , 'batchref' : 'sku2batch' },
2336 ]
@@ -30,6 +43,6 @@ def test_deallocation(sqlite_session_factory):
3043 messagebus .handle (commands .Allocate ('o1' , 'sku1' , 40 ), uow )
3144 messagebus .handle (commands .ChangeBatchQuantity ('b1' , 10 ), uow )
3245
33- assert views .allocations ('o1' , uow ) == [
46+ assert views .allocations ('o1' ) == [
3447 {'sku' : 'sku1' , 'batchref' : 'b2' },
3548 ]
0 commit comments