@@ -56,7 +56,8 @@ def test_add_batch_for_new_product():
5656 event = events .BatchCreated (
5757 reference = "batch1" , sku = "COMPLICATED-LAMP" , qty = 100
5858 )
59- handlers .add_batch (event = event , uow = uow )
59+
60+ messagebus .handle (event , uow )
6061
6162 assert uow .products .get ("COMPLICATED-LAMP" ) is not None
6263 product = uow .products .get ("COMPLICATED-LAMP" )
@@ -66,14 +67,13 @@ def test_add_batch_for_new_product():
6667
6768def test_add_batch_for_existing_product ():
6869 uow = FakeUnitOfWork ()
69- event1 = events .BatchCreated (
70- reference = "batch1" , sku = "CRUNCHY-ARMCHAIR" , qty = 10
71- )
72- event2 = events .BatchCreated (
73- reference = "batch2" , sku = "CRUNCHY-ARMCHAIR" , qty = 15
74- )
75- handlers .add_batch (event = event1 , uow = uow )
76- handlers .add_batch (event = event2 , uow = uow )
70+ event_history = [
71+ events .BatchCreated (reference = "batch1" , sku = "CRUNCHY-ARMCHAIR" , qty = 10 ),
72+ events .BatchCreated (reference = "batch2" , sku = "CRUNCHY-ARMCHAIR" , qty = 15 ),
73+ ]
74+
75+ for event in event_history :
76+ messagebus .handle (event , uow )
7777
7878 assert uow .products .get ("CRUNCHY-ARMCHAIR" ) is not None
7979 product = uow .products .get ("CRUNCHY-ARMCHAIR" )
@@ -87,43 +87,43 @@ def test_allocate_returns_allocation():
8787 event = events .BatchCreated (
8888 reference = "batch1" , sku = "COMPLICATED-LAMP" , qty = 100
8989 )
90- handlers . add_batch (event , uow )
90+ messagebus . handle (event , uow )
9191
9292 event = events .AllocationRequired (
9393 orderid = "order1" , sku = "COMPLICATED-LAMP" , qty = 10
9494 )
95- result = handlers . allocate (event = event , uow = uow )
95+ [ batchref ] = messagebus . handle (event , uow )
9696
97- assert result == "batch1"
97+ assert batchref == "batch1"
9898 assert uow .committed
9999
100100
101101def test_allocate_errors_for_invalid_sku ():
102102 uow = FakeUnitOfWork ()
103103 event = events .BatchCreated (reference = "batch1" , sku = "AREALSKU" , qty = 100 )
104- handlers . add_batch (event , uow )
104+ messagebus . handle (event , uow )
105105
106106 with pytest .raises (
107107 handlers .InvalidSku , match = "Invalid sku NON-EXISTENTSKU"
108108 ):
109109 event = events .AllocationRequired (
110110 orderid = "order1" , sku = "NON-EXISTENTSKU" , qty = 10
111111 )
112- handlers . allocate (event = event , uow = uow )
112+ messagebus . handle (event , uow )
113113
114114
115115def test_deallocate ():
116116 uow = FakeUnitOfWork ()
117117 event = events .BatchCreated (
118118 reference = "batch1" , sku = "COMPLICATED-LAMP" , qty = 100
119119 )
120- handlers . add_batch (event , uow )
120+ messagebus . handle (event , uow )
121121
122122 event = events .AllocationRequired (
123123 orderid = "order1" , sku = "COMPLICATED-LAMP" , qty = 10
124124 )
125- result = handlers . allocate (event = event , uow = uow )
126- assert result == "batch1"
125+ [ batchref ] = messagebus . handle (event , uow )
126+ assert batchref == "batch1"
127127 product = uow .products .get ("COMPLICATED-LAMP" )
128128 batch = product .batches [0 ]
129129 assert batch .reference == "batch1"
@@ -132,7 +132,7 @@ def test_deallocate():
132132 event = events .DeallocationRequired (
133133 orderid = "order1" , sku = "COMPLICATED-LAMP" , qty = 10
134134 )
135- handlers . deallocate (event , uow )
135+ messagebus . handle (event , uow )
136136
137137 assert batch .allocated_quaitity == 0
138138 assert uow .committed
0 commit comments