11from datetime import date , timedelta
22import pytest
3- from allocation .domain .model import allocate , OrderLine , Batch , OutOfStock
3+ from allocation .domain .model import Product , OrderLine , Batch , OutOfStock
44
55today = date .today ()
66tomorrow = today + timedelta (days = 1 )
77later = tomorrow + timedelta (days = 10 )
88
99
10- def test_prefers_current_stock_batches_to_shipments ():
10+ def test_prefers_warehouse_batches_to_shipments ():
1111 in_stock_batch = Batch ("in-stock-batch" , "RETRO-CLOCK" , 100 , eta = None )
1212 shipment_batch = Batch ("shipment-batch" , "RETRO-CLOCK" , 100 , eta = tomorrow )
13+ product = Product (sku = "RETRO-CLOCK" , batches = [in_stock_batch , shipment_batch ])
1314 line = OrderLine ("oref" , "RETRO-CLOCK" , 10 )
1415
15- allocate (line , [ in_stock_batch , shipment_batch ] )
16+ product . allocate (line )
1617
1718 assert in_stock_batch .available_quantity == 90
1819 assert shipment_batch .available_quantity == 100
@@ -22,9 +23,10 @@ def test_prefers_earlier_batches():
2223 earliest = Batch ("speedy-batch" , "MINIMALIST-SPOON" , 100 , eta = today )
2324 medium = Batch ("normal-batch" , "MINIMALIST-SPOON" , 100 , eta = tomorrow )
2425 latest = Batch ("slow-batch" , "MINIMALIST-SPOON" , 100 , eta = later )
26+ product = Product (sku = "MINIMALIST-SPOON" , batches = [medium , earliest , latest ])
2527 line = OrderLine ("order1" , "MINIMALIST-SPOON" , 10 )
2628
27- allocate (line , [ medium , earliest , latest ] )
29+ product . allocate (line )
2830
2931 assert earliest .available_quantity == 90
3032 assert medium .available_quantity == 100
@@ -35,13 +37,15 @@ def test_returns_allocated_batch_ref():
3537 in_stock_batch = Batch ("in-stock-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = None )
3638 shipment_batch = Batch ("shipment-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = tomorrow )
3739 line = OrderLine ("oref" , "HIGHBROW-POSTER" , 10 )
38- allocation = allocate (line , [in_stock_batch , shipment_batch ])
40+ product = Product (sku = "HIGHBROW-POSTER" , batches = [in_stock_batch , shipment_batch ])
41+ allocation = product .allocate (line )
3942 assert allocation == in_stock_batch .reference
4043
4144
4245def test_raises_out_of_stock_exception_if_cannot_allocate ():
4346 batch = Batch ("batch1" , "SMALL-FORK" , 10 , eta = today )
44- allocate (OrderLine ("order1" , "SMALL-FORK" , 10 ), [batch ])
47+ product = Product (sku = "SMALL-FORK" , batches = [batch ])
48+ product .allocate (OrderLine ("order1" , "SMALL-FORK" , 10 ))
4549
4650 with pytest .raises (OutOfStock , match = "SMALL-FORK" ):
47- allocate (OrderLine ("order2" , "SMALL-FORK" , 1 ), [ batch ] )
51+ product . allocate (OrderLine ("order2" , "SMALL-FORK" , 1 ))
0 commit comments