66later = tomorrow + timedelta (days = 10 )
77
88Order = lambda d : domain_model .Order (lines = [domain_model .OrderLine (sku , qty ) for sku , qty in d .items ()])
9- Stock = lambda d : domain_model .Stock (lines = [domain_model .OrderLine (sku , qty ) for sku , qty in d .items ()])
9+ Warehouse = lambda d : domain_model .Warehouse (lines = [domain_model .OrderLine (sku , qty ) for sku , qty in d .items ()])
1010Shipment = lambda d , eta : domain_model .Shipment (
1111 lines = [domain_model .OrderLine (sku , qty ) for sku , qty in d .items ()],
1212 eta = eta ,
1313)
1414
1515
16- def test_can_allocate_to_stock ():
16+ def test_can_allocate_to_warehouse ():
1717 order = Order ({'a-sku' : 10 })
18- stock = Stock ({'a-sku' : 1000 })
18+ warehouse = Warehouse ({'a-sku' : 1000 })
1919
20- order .allocate (stock , shipments = [])
20+ order .allocate (warehouse , shipments = [])
2121
22- assert order .allocation .sources ['a-sku' ] == stock
23- assert stock .quantities ['a-sku' ] == 990
22+ assert order .allocation .sources ['a-sku' ] == warehouse
23+ assert warehouse .quantities ['a-sku' ] == 990
2424
2525
2626def test_can_allocate_to_shipment ():
2727 order = Order ({'a-sku' : 10 })
2828 shipment = Shipment ({'a-sku' : 1000 }, eta = tomorrow )
2929
30- order .allocate (stock = Stock ({}), shipments = [shipment ])
30+ order .allocate (warehouse = Warehouse ({}), shipments = [shipment ])
3131
3232 assert order .allocation .sources ['a-sku' ] == shipment
3333 assert shipment .quantities ['a-sku' ] == 990
3434
3535
36- def test_ignores_irrelevant_stock ():
36+ def test_ignores_irrelevant_warehouse ():
3737 order = Order ({'sku1' : 10 })
38- stock = Stock ({'sku2' : 1000 })
38+ warehouse = Warehouse ({'sku2' : 1000 })
3939 shipment = Shipment ({'sku1' : 1000 }, eta = tomorrow )
4040
41- order .allocate (stock = stock , shipments = [shipment ])
41+ order .allocate (warehouse = warehouse , shipments = [shipment ])
4242
4343 assert order .allocation .sources ['sku1' ] == shipment
4444
@@ -49,39 +49,39 @@ def test_can_allocate_to_correct_shipment():
4949 shipment1 = Shipment ({'sku1' : 1000 }, eta = tomorrow )
5050 shipment2 = Shipment ({'sku2' : 1000 }, eta = tomorrow )
5151
52- order .allocate (stock = Stock ({}), shipments = [shipment1 , shipment2 ])
52+ order .allocate (warehouse = Warehouse ({}), shipments = [shipment1 , shipment2 ])
5353
5454 assert order .allocation .sources ['sku2' ] == shipment2
5555
5656
57- def test_allocates_to_stock_in_preference_to_shipment ():
57+ def test_allocates_to_warehouse_in_preference_to_shipment ():
5858 order = Order ({'sku1' : 10 })
59- stock = Stock ({'sku1' : 1000 })
59+ warehouse = Warehouse ({'sku1' : 1000 })
6060 shipment = Shipment ({'sku1' : 1000 }, eta = tomorrow )
6161
62- order .allocate (stock , shipments = [shipment ])
62+ order .allocate (warehouse , shipments = [shipment ])
6363
64- assert order .allocation .sources ['sku1' ] == stock
65- assert stock .quantities ['sku1' ] == 990
64+ assert order .allocation .sources ['sku1' ] == warehouse
65+ assert warehouse .quantities ['sku1' ] == 990
6666 assert shipment .quantities ['sku1' ] == 1000
6767
6868
6969def test_can_allocate_multiple_lines_to_wh ():
7070 order = Order ({'sku1' : 5 , 'sku2' : 10 })
71- stock = Stock ({'sku1' : 1000 , 'sku2' : 1000 })
71+ warehouse = Warehouse ({'sku1' : 1000 , 'sku2' : 1000 })
7272
73- order .allocate (stock , shipments = [])
74- assert order .allocation .sources ['sku1' ] == stock
75- assert order .allocation .sources ['sku2' ] == stock
76- assert stock .quantities ['sku1' ] == 995
77- assert stock .quantities ['sku2' ] == 990
73+ order .allocate (warehouse , shipments = [])
74+ assert order .allocation .sources ['sku1' ] == warehouse
75+ assert order .allocation .sources ['sku2' ] == warehouse
76+ assert warehouse .quantities ['sku1' ] == 995
77+ assert warehouse .quantities ['sku2' ] == 990
7878
7979
8080def test_can_allocate_multiple_lines_to_shipment ():
8181 order = Order ({'sku1' : 5 , 'sku2' : 10 })
8282 shipment = Shipment ({'sku1' : 1000 , 'sku2' : 1000 }, eta = tomorrow )
8383
84- order .allocate (stock = Stock ({}), shipments = [shipment ])
84+ order .allocate (warehouse = Warehouse ({}), shipments = [shipment ])
8585
8686 assert order .allocation .sources ['sku1' ] == shipment
8787 assert order .allocation .sources ['sku2' ] == shipment
@@ -92,41 +92,41 @@ def test_can_allocate_multiple_lines_to_shipment():
9292def test_can_allocate_to_both ():
9393 order = Order ({'sku1' : 5 , 'sku2' : 10 })
9494 shipment = Shipment ({'sku2' : 1000 }, eta = tomorrow )
95- stock = Stock ({'sku1' : 1000 })
95+ warehouse = Warehouse ({'sku1' : 1000 })
9696
97- order .allocate (stock , shipments = [shipment ])
97+ order .allocate (warehouse , shipments = [shipment ])
9898
99- assert order .allocation .sources ['sku1' ] == stock
99+ assert order .allocation .sources ['sku1' ] == warehouse
100100 assert order .allocation .sources ['sku2' ] == shipment
101- assert stock .quantities ['sku1' ] == 995
101+ assert warehouse .quantities ['sku1' ] == 995
102102 assert shipment .quantities ['sku2' ] == 990
103103
104104
105- def test_can_allocate_to_both_preferring_stock ():
105+ def test_can_allocate_to_both_preferring_warehouse ():
106106 order = Order ({'sku1' : 1 , 'sku2' : 2 , 'sku3' : 3 , 'sku4' : 4 })
107107 shipment = Shipment ({'sku1' : 1000 , 'sku2' : 1000 , 'sku3' : 1000 }, eta = tomorrow )
108- stock = Stock ({'sku3' : 1000 , 'sku4' : 1000 })
108+ warehouse = Warehouse ({'sku3' : 1000 , 'sku4' : 1000 })
109109
110- order .allocate (stock , shipments = [shipment ])
110+ order .allocate (warehouse , shipments = [shipment ])
111111
112112 assert order .allocation .sources ['sku1' ] == shipment
113113 assert order .allocation .sources ['sku2' ] == shipment
114- assert order .allocation .sources ['sku3' ] == stock
115- assert order .allocation .sources ['sku4' ] == stock
114+ assert order .allocation .sources ['sku3' ] == warehouse
115+ assert order .allocation .sources ['sku4' ] == warehouse
116116 assert shipment .quantities ['sku1' ] == 999
117117 assert shipment .quantities ['sku2' ] == 998
118118 assert shipment .quantities ['sku3' ] == 1000
119- assert stock .quantities ['sku3' ] == 997
120- assert stock .quantities ['sku4' ] == 996
119+ assert warehouse .quantities ['sku3' ] == 997
120+ assert warehouse .quantities ['sku4' ] == 996
121121
122122
123123def test_allocated_to_earliest_suitable_shipment_in_list ():
124124 order = Order ({'sku1' : 10 , 'sku2' : 10 })
125125 shipment1 = Shipment ({'sku1' : 1000 , 'sku2' : 1000 }, eta = today )
126126 shipment2 = Shipment ({'sku1' : 1000 , 'sku2' : 1000 }, eta = tomorrow )
127- stock = Stock ({})
127+ warehouse = Warehouse ({})
128128
129- order .allocate (stock , shipments = [shipment2 , shipment1 ])
129+ order .allocate (warehouse , shipments = [shipment2 , shipment1 ])
130130
131131 assert order .allocation .sources ['sku1' ] == shipment1
132132 assert order .allocation .sources ['sku2' ] == shipment1
@@ -137,34 +137,34 @@ def test_still_chooses_earliest_if_split_across_shipments():
137137 shipment1 = Shipment ({'sku1' : 1000 }, eta = today )
138138 shipment2 = Shipment ({'sku2' : 1000 , 'sku3' : 1000 }, eta = tomorrow )
139139 shipment3 = Shipment ({'sku2' : 1000 , 'sku3' : 1000 }, eta = later )
140- stock = Stock ({})
140+ warehouse = Warehouse ({})
141141
142- order .allocate (stock , shipments = [shipment3 , shipment2 , shipment1 ])
142+ order .allocate (warehouse , shipments = [shipment3 , shipment2 , shipment1 ])
143143
144144 assert order .allocation .sources ['sku1' ] == shipment1
145145 assert order .allocation .sources ['sku2' ] == shipment2
146146 assert order .allocation .sources ['sku3' ] == shipment2
147147
148148
149- def test_stock_not_quite_enough_means_we_use_shipment ():
149+ def test_warehouse_not_quite_enough_means_we_use_shipment ():
150150 order = Order ({'sku1' : 10 , 'sku2' : 10 })
151- stock = Stock ({'sku1' : 10 , 'sku2' : 5 })
151+ warehouse = Warehouse ({'sku1' : 10 , 'sku2' : 5 })
152152 shipment = Shipment ({
153153 'sku1' : 1000 ,
154154 'sku2' : 1000 ,
155155 }, eta = tomorrow )
156156
157- order .allocate (stock , shipments = [shipment ])
157+ order .allocate (warehouse , shipments = [shipment ])
158158
159159 assert order .allocation .sources ['sku1' ] == shipment
160160 assert order .allocation .sources ['sku2' ] == shipment
161161
162162
163- def test_cannot_allocate_if_insufficent_quantity_in_stock ():
163+ def test_cannot_allocate_if_insufficent_quantity_in_warehouse ():
164164 order = Order ({'a-sku' : 10 })
165- stock = Stock ({'a-sku' : 5 })
165+ warehouse = Warehouse ({'a-sku' : 5 })
166166
167- order .allocate (stock , shipments = [])
167+ order .allocate (warehouse , shipments = [])
168168
169169 assert 'a-sku' not in order .allocation .skus
170170
@@ -173,7 +173,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
173173 order = Order ({'a-sku' : 10 })
174174 shipment = Shipment ({'a-sku' : 5 }, eta = tomorrow )
175175
176- order .allocate (stock = Stock ({}), shipments = [shipment ])
176+ order .allocate (warehouse = Warehouse ({}), shipments = [shipment ])
177177
178178 assert 'a-sku' not in order .allocation .skus
179179
0 commit comments