Skip to content

Commit c3ce4f0

Browse files
committed
s/stock/warehouse/
1 parent 0e511f7 commit c3ce4f0

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

domain_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class Order(dict):
22

3-
def allocate(self, stock, shipments):
4-
self.allocation = self.find_allocation(stock, shipments)
3+
def allocate(self, warehouse, shipments):
4+
self.allocation = self.find_allocation(warehouse, shipments)
55
self.decrement_source_quantities()
66

7-
def find_allocation(self, stock, shipments):
8-
ordered_sources = [stock] + sorted(shipments)
7+
def find_allocation(self, warehouse, shipments):
8+
ordered_sources = [warehouse] + sorted(shipments)
99
allocation = {}
1010
for source in reversed(ordered_sources):
1111
allocation.update(source.allocation_for(self))
@@ -17,7 +17,7 @@ def decrement_source_quantities(self):
1717

1818

1919

20-
class Stock(dict):
20+
class Warehouse(dict):
2121

2222
def allocation_for(self, order):
2323
return {
@@ -28,7 +28,7 @@ def allocation_for(self, order):
2828
}
2929

3030

31-
class Shipment(Stock):
31+
class Shipment(Warehouse):
3232

3333
def __init__(self, d, eta):
3434
self.eta = eta

test_allocation.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
from domain_model import Order, Stock, Shipment
1+
from domain_model import Order, Warehouse, Shipment
22
from datetime import date, timedelta
33

44
today = date.today()
55
tomorrow = today + timedelta(days=1)
66
later = tomorrow + timedelta(days=10)
77

88

9-
def test_can_allocate_to_stock():
9+
def test_can_allocate_to_warehouse():
1010
order = Order({'a-sku': 10})
11-
stock = Stock({'a-sku': 1000})
11+
warehouse = Warehouse({'a-sku': 1000})
1212

13-
order.allocate(stock, shipments=[])
13+
order.allocate(warehouse, shipments=[])
1414

15-
assert order.allocation['a-sku'] == stock
16-
assert stock['a-sku'] == 990
15+
assert order.allocation['a-sku'] == warehouse
16+
assert warehouse['a-sku'] == 990
1717

1818

1919
def test_can_allocate_to_shipment():
2020
order = Order({'a-sku': 10})
2121
shipment = Shipment({'a-sku': 1000}, eta=tomorrow)
2222

23-
order.allocate(stock=Stock({}), shipments=[shipment])
23+
order.allocate(warehouse=Warehouse({}), shipments=[shipment])
2424

2525
assert order.allocation['a-sku'] == shipment
2626
assert shipment['a-sku'] == 990
2727

2828

29-
def test_ignores_irrelevant_stock():
29+
def test_ignores_irrelevant_warehouse():
3030
order = Order({'sku1': 10})
31-
stock = Stock({'sku2': 1000})
31+
warehouse = Warehouse({'sku2': 1000})
3232
shipment = Shipment({'sku1': 1000}, eta=tomorrow)
3333

34-
order.allocate(stock=stock, shipments=[shipment])
34+
order.allocate(warehouse=warehouse, shipments=[shipment])
3535

3636
assert order.allocation['sku1'] == shipment
3737

@@ -42,39 +42,39 @@ def test_can_allocate_to_correct_shipment():
4242
shipment1 = Shipment({'sku1': 1000}, eta=tomorrow)
4343
shipment2 = Shipment({'sku2': 1000}, eta=tomorrow)
4444

45-
order.allocate(stock=Stock({}), shipments=[shipment1, shipment2])
45+
order.allocate(warehouse=Warehouse({}), shipments=[shipment1, shipment2])
4646

4747
assert order.allocation['sku2'] == shipment2
4848

4949

50-
def test_allocates_to_stock_in_preference_to_shipment():
50+
def test_allocates_to_warehouse_in_preference_to_shipment():
5151
order = Order({'sku1': 10})
52-
stock = Stock({'sku1': 1000})
52+
warehouse = Warehouse({'sku1': 1000})
5353
shipment = Shipment({'sku1': 1000}, eta=tomorrow)
5454

55-
order.allocate(stock, shipments=[shipment])
55+
order.allocate(warehouse, shipments=[shipment])
5656

57-
assert order.allocation['sku1'] == stock
58-
assert stock['sku1'] == 990
57+
assert order.allocation['sku1'] == warehouse
58+
assert warehouse['sku1'] == 990
5959
assert shipment['sku1'] == 1000
6060

6161

6262
def test_can_allocate_multiple_lines_to_wh():
6363
order = Order({'sku1': 5, 'sku2': 10})
64-
stock = Stock({'sku1': 1000, 'sku2': 1000})
64+
warehouse = Warehouse({'sku1': 1000, 'sku2': 1000})
6565

66-
order.allocate(stock, shipments=[])
67-
assert order.allocation['sku1'] == stock
68-
assert order.allocation['sku2'] == stock
69-
assert stock['sku1'] == 995
70-
assert stock['sku2'] == 990
66+
order.allocate(warehouse, shipments=[])
67+
assert order.allocation['sku1'] == warehouse
68+
assert order.allocation['sku2'] == warehouse
69+
assert warehouse['sku1'] == 995
70+
assert warehouse['sku2'] == 990
7171

7272

7373
def test_can_allocate_multiple_lines_to_shipment():
7474
order = Order({'sku1': 5, 'sku2': 10})
7575
shipment = Shipment({'sku1': 1000, 'sku2': 1000}, eta=tomorrow)
7676

77-
order.allocate(stock=Stock({}), shipments=[shipment])
77+
order.allocate(warehouse=Warehouse({}), shipments=[shipment])
7878

7979
assert order.allocation['sku1'] == shipment
8080
assert order.allocation['sku2'] == shipment
@@ -85,41 +85,41 @@ def test_can_allocate_multiple_lines_to_shipment():
8585
def test_can_allocate_to_both():
8686
order = Order({'sku1': 5, 'sku2': 10})
8787
shipment = Shipment({'sku2': 1000}, eta=tomorrow)
88-
stock = Stock({'sku1': 1000})
88+
warehouse = Warehouse({'sku1': 1000})
8989

90-
order.allocate(stock, shipments=[shipment])
90+
order.allocate(warehouse, shipments=[shipment])
9191

92-
assert order.allocation['sku1'] == stock
92+
assert order.allocation['sku1'] == warehouse
9393
assert order.allocation['sku2'] == shipment
94-
assert stock['sku1'] == 995
94+
assert warehouse['sku1'] == 995
9595
assert shipment['sku2'] == 990
9696

9797

98-
def test_can_allocate_to_both_preferring_stock():
98+
def test_can_allocate_to_both_preferring_warehouse():
9999
order = Order({'sku1': 1, 'sku2': 2, 'sku3': 3, 'sku4': 4})
100100
shipment = Shipment({'sku1': 1000, 'sku2': 1000, 'sku3': 1000}, eta=tomorrow)
101-
stock = Stock({'sku3': 1000, 'sku4': 1000})
101+
warehouse = Warehouse({'sku3': 1000, 'sku4': 1000})
102102

103-
order.allocate(stock, shipments=[shipment])
103+
order.allocate(warehouse, shipments=[shipment])
104104

105105
assert order.allocation['sku1'] == shipment
106106
assert order.allocation['sku2'] == shipment
107-
assert order.allocation['sku3'] == stock
108-
assert order.allocation['sku4'] == stock
107+
assert order.allocation['sku3'] == warehouse
108+
assert order.allocation['sku4'] == warehouse
109109
assert shipment['sku1'] == 999
110110
assert shipment['sku2'] == 998
111111
assert shipment['sku3'] == 1000
112-
assert stock['sku3'] == 997
113-
assert stock['sku4'] == 996
112+
assert warehouse['sku3'] == 997
113+
assert warehouse['sku4'] == 996
114114

115115

116116
def test_allocated_to_earliest_suitable_shipment_in_list():
117117
order = Order({'sku1': 10, 'sku2': 10})
118118
shipment1 = Shipment({'sku1': 1000, 'sku2': 1000}, eta=today)
119119
shipment2 = Shipment({'sku1': 1000, 'sku2': 1000}, eta=tomorrow)
120-
stock = Stock({})
120+
warehouse = Warehouse({})
121121

122-
order.allocate(stock, shipments=[shipment1, shipment2])
122+
order.allocate(warehouse, shipments=[shipment1, shipment2])
123123

124124
assert order.allocation['sku1'] == shipment1
125125
assert order.allocation['sku2'] == shipment1
@@ -130,34 +130,34 @@ def test_still_chooses_earliest_if_split_across_shipments():
130130
shipment1 = Shipment({'sku1': 1000}, eta=today)
131131
shipment2 = Shipment({'sku2': 1000, 'sku3': 1000}, eta=tomorrow)
132132
shipment3 = Shipment({'sku2': 1000, 'sku3': 1000}, eta=later)
133-
stock = Stock({})
133+
warehouse = Warehouse({})
134134

135-
order.allocate(stock, shipments=[shipment2, shipment3, shipment1])
135+
order.allocate(warehouse, shipments=[shipment2, shipment3, shipment1])
136136

137137
assert order.allocation['sku1'] == shipment1
138138
assert order.allocation['sku2'] == shipment2
139139
assert order.allocation['sku3'] == shipment2
140140

141141

142-
def test_stock_not_quite_enough_means_we_use_shipment():
142+
def test_warehouse_not_quite_enough_means_we_use_shipment():
143143
order = Order({'sku1': 10, 'sku2': 10})
144-
stock = Stock({'sku1': 10, 'sku2': 5})
144+
warehouse = Warehouse({'sku1': 10, 'sku2': 5})
145145
shipment = Shipment({
146146
'sku1': 1000,
147147
'sku2': 1000,
148148
}, eta=tomorrow)
149149

150-
order.allocate(stock, shipments=[shipment])
150+
order.allocate(warehouse, shipments=[shipment])
151151

152152
assert order.allocation['sku1'] == shipment
153153
assert order.allocation['sku2'] == shipment
154154

155155

156-
def test_cannot_allocate_if_insufficent_quantity_in_stock():
156+
def test_cannot_allocate_if_insufficent_quantity_in_warehouse():
157157
order = Order({'a-sku': 10})
158-
stock = Stock({'a-sku': 5})
158+
warehouse = Warehouse({'a-sku': 5})
159159

160-
order.allocate(stock, shipments=[])
160+
order.allocate(warehouse, shipments=[])
161161

162162
assert 'a-sku' not in order.allocation
163163

@@ -166,7 +166,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
166166
order = Order({'a-sku': 10})
167167
shipment = Shipment({'a-sku': 5}, eta=tomorrow)
168168

169-
order.allocate(stock=Stock({}), shipments=[shipment])
169+
order.allocate(warehouse=Warehouse({}), shipments=[shipment])
170170

171171
assert 'a-sku' not in order.allocation
172172

0 commit comments

Comments
 (0)