@@ -12,10 +12,10 @@ def test_prefers_current_stock_batches_to_shipments():
1212 shipment_batch = Batch ("shipment-batch" , "RETRO-CLOCK" , 100 , eta = tomorrow )
1313 line = OrderLine ("oref" , "RETRO-CLOCK" , 10 )
1414
15- allocate (line , [in_stock_batch , shipment_batch ])
15+ updated_batch = allocate (line , [in_stock_batch , shipment_batch ])
1616
17- assert in_stock_batch . available_quantity == 90
18- assert shipment_batch .available_quantity == 100
17+ assert updated_batch . ref == in_stock_batch . ref
18+ assert updated_batch .available_quantity == 90
1919
2020
2121def test_prefers_earlier_batches ():
@@ -24,24 +24,17 @@ def test_prefers_earlier_batches():
2424 latest = Batch ("slow-batch" , "MINIMALIST-SPOON" , 100 , eta = later )
2525 line = OrderLine ("order1" , "MINIMALIST-SPOON" , 10 )
2626
27- allocate (line , [medium , earliest , latest ])
27+ updated_batch = allocate (line , [medium , earliest , latest ])
2828
29- assert earliest .available_quantity == 90
30- assert medium .available_quantity == 100
31- assert latest .available_quantity == 100
32-
33-
34- def test_returns_allocated_batch_ref ():
35- in_stock_batch = Batch ("in-stock-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = None )
36- shipment_batch = Batch ("shipment-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = tomorrow )
37- line = OrderLine ("oref" , "HIGHBROW-POSTER" , 10 )
38- allocation = allocate (line , [in_stock_batch , shipment_batch ])
39- assert allocation == in_stock_batch .reference
29+ assert updated_batch .ref == earliest .ref
30+ assert updated_batch .available_quantity == 90
4031
4132
4233def test_raises_out_of_stock_exception_if_cannot_allocate ():
4334 batch = Batch ("batch1" , "SMALL-FORK" , 10 , eta = today )
44- allocate (OrderLine ("order1" , "SMALL-FORK" , 10 ), [batch ])
35+ updated_batch = allocate (OrderLine ("order1" , "SMALL-FORK" , 10 ), [batch ])
36+ assert updated_batch
4537
4638 with pytest .raises (OutOfStock , match = "SMALL-FORK" ):
47- allocate (OrderLine ("order2" , "SMALL-FORK" , 1 ), [batch ])
39+ result = allocate (OrderLine ("order2" , "SMALL-FORK" , 1 ), [updated_batch ])
40+ assert result is None
0 commit comments