3
3
4
4
5
5
from domain_model import (
6
- Line ,
7
6
OrderLine ,
8
7
Shipment ,
9
8
allocate ,
@@ -18,12 +17,12 @@ def random_id():
18
17
19
18
def test_can_allocate_to_stock ():
20
19
order = [OrderLine (sku = 'a-sku' , quantity = 10 )]
21
- stock = [ Line ( sku = 'a-sku' , quantity = 1000 )]
20
+ stock = { 'a-sku' : 1000 }
22
21
23
22
allocate (order , stock , shipments = [])
24
23
25
24
assert order [0 ].allocation == 'STOCK'
26
- assert stock [0 ]. quantity == 990
25
+ assert stock ['a-sku' ] == 990
27
26
28
27
29
28
def test_can_allocate_to_shipment ():
@@ -38,17 +37,17 @@ def test_can_allocate_to_shipment():
38
37
assert shipment ['a-sku' ] == 990
39
38
40
39
41
- def test_ignores_invalid_stock ():
40
+ def test_ignores_irrelevant_stock ():
42
41
order = [OrderLine (sku = 'sku1' , quantity = 10 ), ]
43
- stock = [ Line ( sku = 'sku2' , quantity = 1000 )]
42
+ stock = { 'sku2' : 1000 }
44
43
shipment = Shipment (id = 'shipment-id' , eta = date .today (), lines = {
45
44
'sku1' : 1000 ,
46
45
})
47
46
48
47
allocate (order , stock = stock , shipments = [shipment ])
49
48
50
49
assert order [0 ].allocation == shipment .id
51
- assert stock [0 ]. quantity == 1000
50
+ assert stock ['sku2' ] == 1000
52
51
assert shipment ['sku1' ] == 990
53
52
54
53
@@ -70,15 +69,15 @@ def test_can_allocate_to_correct_shipment():
70
69
71
70
def test_allocates_to_stock_in_preference_to_shipment ():
72
71
order = [OrderLine (sku = 'sku1' , quantity = 10 )]
73
- stock = [ Line ( sku = 'sku1' , quantity = 1000 )]
72
+ stock = { 'sku1' : 1000 }
74
73
shipment = Shipment ('shipment1' , eta = date .today (), lines = {
75
74
'sku1' : 1000 ,
76
75
})
77
76
78
77
allocate (order , stock , shipments = [shipment ])
79
78
80
79
assert order [0 ].allocation == 'STOCK'
81
- assert stock [0 ]. quantity == 990
80
+ assert stock ['sku1' ] == 990
82
81
assert shipment ['sku1' ] == 1000
83
82
84
83
@@ -87,16 +86,13 @@ def test_can_allocate_multiple_lines_to_wh():
87
86
OrderLine (sku = 'sku1' , quantity = 5 ),
88
87
OrderLine (sku = 'sku2' , quantity = 10 ),
89
88
]
90
- stock = [
91
- Line (sku = 'sku1' , quantity = 1000 ),
92
- Line (sku = 'sku2' , quantity = 1000 ),
93
- ]
89
+ stock = {'sku1' : 1000 , 'sku2' : 1000 }
94
90
95
91
allocate (order , stock , shipments = [])
96
92
assert order [0 ].allocation == 'STOCK'
97
93
assert order [1 ].allocation == 'STOCK'
98
- assert stock [0 ]. quantity == 995
99
- assert stock [1 ]. quantity == 990
94
+ assert stock ['sku1' ] == 995
95
+ assert stock ['sku2' ] == 990
100
96
101
97
102
98
def test_can_allocate_multiple_lines_to_shipment ():
@@ -125,13 +121,13 @@ def test_can_allocate_to_both():
125
121
shipment = Shipment ('shipment1' , eta = date .today (), lines = {
126
122
'sku2' : 1000 ,
127
123
})
128
- stock = [ Line ( sku = 'sku1' , quantity = 1000 )]
124
+ stock = { 'sku1' : 1000 }
129
125
130
126
allocate (order , stock , shipments = [shipment ])
131
127
132
128
assert order [0 ].allocation == 'STOCK'
133
129
assert order [1 ].allocation == shipment .id
134
- assert stock [0 ]. quantity == 995
130
+ assert stock ['sku1' ] == 995
135
131
assert shipment ['sku2' ] == 990
136
132
137
133
@@ -147,10 +143,7 @@ def test_can_allocate_to_both_preferring_stock():
147
143
'sku2' : 1000 ,
148
144
'sku3' : 1000 ,
149
145
})
150
- stock = [
151
- Line (sku = 'sku3' , quantity = 1000 ),
152
- Line (sku = 'sku4' , quantity = 1000 ),
153
- ]
146
+ stock = {'sku3' : 1000 , 'sku4' : 1000 }
154
147
155
148
allocate (order , stock , shipments = [shipment ])
156
149
@@ -161,8 +154,8 @@ def test_can_allocate_to_both_preferring_stock():
161
154
assert shipment ['sku1' ] == 999
162
155
assert shipment ['sku2' ] == 998
163
156
assert shipment ['sku3' ] == 1000
164
- assert stock [0 ]. quantity == 997
165
- assert stock [1 ]. quantity == 996
157
+ assert stock ['sku3' ] == 997
158
+ assert stock ['sku4' ] == 996
166
159
167
160
168
161
def test_mixed_allocations_are_avoided_if_possible ():
@@ -174,7 +167,7 @@ def test_mixed_allocations_are_avoided_if_possible():
174
167
'sku1' : 1000 ,
175
168
'sku2' : 1000 ,
176
169
})
177
- stock = [ Line ( sku = 'sku1' , quantity = 1000 )]
170
+ stock = { 'sku1' : 1000 }
178
171
179
172
allocate (order , stock , shipments = [shipment ])
180
173
@@ -196,7 +189,7 @@ def test_prefer_allocating_to_earlier_shipment():
196
189
'sku1' : 1000 ,
197
190
'sku2' : 1000 ,
198
191
})
199
- stock = []
192
+ stock = {}
200
193
201
194
allocate (order , stock , shipments = [shipment2 , shipment1 ])
202
195
@@ -233,7 +226,7 @@ def test_prefer_allocating_to_earlier_even_if_multiple_shipments():
233
226
234
227
def test_cannot_allocate_if_insufficent_quantity_in_stock ():
235
228
order = [OrderLine (sku = 'a-sku' , quantity = 10 )]
236
- stock = [ Line ( sku = 'a-sku' , quantity = 5 )]
229
+ stock = { 'a-sku' : 5 }
237
230
238
231
allocate (order , stock , shipments = [])
239
232
@@ -254,7 +247,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
254
247
def test_cannot_allocate_more_orders_than_we_have_stock_for ():
255
248
order1 = [OrderLine (sku = 'a-sku' , quantity = 10 )]
256
249
order2 = [OrderLine (sku = 'a-sku' , quantity = 10 )]
257
- stock = [ Line ( sku = 'a-sku' , quantity = 15 )]
250
+ stock = { 'a-sku' : 15 }
258
251
259
252
allocate (order1 , stock , shipments = [])
260
253
allocate (order2 , stock , shipments = [])
0 commit comments