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
9- def test_prefers_current_stock_batches_to_shipments ():
9+ def test_prefers_warehouse_batches_to_shipments ():
1010 in_stock_batch = Batch ("in-stock-batch" , "RETRO-CLOCK" , 100 , eta = None )
1111 shipment_batch = Batch ("shipment-batch" , "RETRO-CLOCK" , 100 , eta = tomorrow )
12+ product = Product (sku = "RETRO-CLOCK" , batches = [in_stock_batch , shipment_batch ])
1213 line = OrderLine ("oref" , "RETRO-CLOCK" , 10 )
1314
14- allocate (line , [ in_stock_batch , shipment_batch ] )
15+ product . allocate (line )
1516
1617 assert in_stock_batch .available_quantity == 90
1718 assert shipment_batch .available_quantity == 100
@@ -21,9 +22,10 @@ def test_prefers_earlier_batches():
2122 earliest = Batch ("speedy-batch" , "MINIMALIST-SPOON" , 100 , eta = today )
2223 medium = Batch ("normal-batch" , "MINIMALIST-SPOON" , 100 , eta = tomorrow )
2324 latest = Batch ("slow-batch" , "MINIMALIST-SPOON" , 100 , eta = later )
25+ product = Product (sku = "MINIMALIST-SPOON" , batches = [medium , earliest , latest ])
2426 line = OrderLine ("order1" , "MINIMALIST-SPOON" , 10 )
2527
26- allocate (line , [ medium , earliest , latest ] )
28+ product . allocate (line )
2729
2830 assert earliest .available_quantity == 90
2931 assert medium .available_quantity == 100
@@ -34,13 +36,15 @@ def test_returns_allocated_batch_ref():
3436 in_stock_batch = Batch ("in-stock-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = None )
3537 shipment_batch = Batch ("shipment-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = tomorrow )
3638 line = OrderLine ("oref" , "HIGHBROW-POSTER" , 10 )
37- allocation = allocate (line , [in_stock_batch , shipment_batch ])
39+ product = Product (sku = "HIGHBROW-POSTER" , batches = [in_stock_batch , shipment_batch ])
40+ allocation = product .allocate (line )
3841 assert allocation == in_stock_batch .reference
3942
4043
4144def test_raises_out_of_stock_exception_if_cannot_allocate ():
4245 batch = Batch ('batch1' , 'SMALL-FORK' , 10 , eta = today )
43- allocate (OrderLine ('order1' , 'SMALL-FORK' , 10 ), [batch ])
46+ product = Product (sku = "SMALL-FORK" , batches = [batch ])
47+ product .allocate (OrderLine ('order1' , 'SMALL-FORK' , 10 ))
4448
4549 with pytest .raises (OutOfStock , match = 'SMALL-FORK' ):
46- allocate (OrderLine ('order2' , 'SMALL-FORK' , 1 ), [ batch ] )
50+ product . allocate (OrderLine ('order2' , 'SMALL-FORK' , 1 ))
0 commit comments