1
1
from datetime import date , timedelta
2
2
import pytest
3
- from allocation .domain .model import allocate , OrderLine , Batch , OutOfStock
3
+ from allocation .domain .model import Product , OrderLine , Batch , OutOfStock
4
4
5
5
today = date .today ()
6
6
tomorrow = today + timedelta (days = 1 )
7
7
later = tomorrow + timedelta (days = 10 )
8
8
9
- def test_prefers_current_stock_batches_to_shipments ():
9
+ def test_prefers_warehouse_batches_to_shipments ():
10
10
in_stock_batch = Batch ("in-stock-batch" , "RETRO-CLOCK" , 100 , eta = None )
11
11
shipment_batch = Batch ("shipment-batch" , "RETRO-CLOCK" , 100 , eta = tomorrow )
12
+ product = Product (sku = "RETRO-CLOCK" , batches = [in_stock_batch , shipment_batch ])
12
13
line = OrderLine ("oref" , "RETRO-CLOCK" , 10 )
13
14
14
- allocate (line , [ in_stock_batch , shipment_batch ] )
15
+ product . allocate (line )
15
16
16
17
assert in_stock_batch .available_quantity == 90
17
18
assert shipment_batch .available_quantity == 100
@@ -21,9 +22,10 @@ def test_prefers_earlier_batches():
21
22
earliest = Batch ("speedy-batch" , "MINIMALIST-SPOON" , 100 , eta = today )
22
23
medium = Batch ("normal-batch" , "MINIMALIST-SPOON" , 100 , eta = tomorrow )
23
24
latest = Batch ("slow-batch" , "MINIMALIST-SPOON" , 100 , eta = later )
25
+ product = Product (sku = "MINIMALIST-SPOON" , batches = [medium , earliest , latest ])
24
26
line = OrderLine ("order1" , "MINIMALIST-SPOON" , 10 )
25
27
26
- allocate (line , [ medium , earliest , latest ] )
28
+ product . allocate (line )
27
29
28
30
assert earliest .available_quantity == 90
29
31
assert medium .available_quantity == 100
@@ -34,13 +36,15 @@ def test_returns_allocated_batch_ref():
34
36
in_stock_batch = Batch ("in-stock-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = None )
35
37
shipment_batch = Batch ("shipment-batch-ref" , "HIGHBROW-POSTER" , 100 , eta = tomorrow )
36
38
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 )
38
41
assert allocation == in_stock_batch .reference
39
42
40
43
41
44
def test_raises_out_of_stock_exception_if_cannot_allocate ():
42
45
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 ))
44
48
45
49
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