1
- from domain_model import Order , Warehouse , Shipment
1
+ from domain_model import allocate , Order , Warehouse , Shipment
2
2
from datetime import date , timedelta
3
3
4
4
today = date .today ()
@@ -10,19 +10,19 @@ def test_can_allocate_to_warehouse():
10
10
order = Order ({'a-sku' : 10 })
11
11
warehouse = Warehouse ({'a-sku' : 1000 })
12
12
13
- order . allocate (warehouse , shipments = [])
13
+ allocation = allocate (order , warehouse , shipments = [])
14
14
15
- assert order . allocation ['a-sku' ] == warehouse
15
+ assert allocation ['a-sku' ] == warehouse
16
16
assert warehouse ['a-sku' ] == 990
17
17
18
18
19
19
def test_can_allocate_to_shipment ():
20
20
order = Order ({'a-sku' : 10 })
21
21
shipment = Shipment ({'a-sku' : 1000 }, eta = tomorrow )
22
22
23
- order . allocate (warehouse = Warehouse ({}), shipments = [shipment ])
23
+ allocation = allocate (order , warehouse = Warehouse ({}), shipments = [shipment ])
24
24
25
- assert order . allocation ['a-sku' ] == shipment
25
+ assert allocation ['a-sku' ] == shipment
26
26
assert shipment ['a-sku' ] == 990
27
27
28
28
@@ -31,9 +31,9 @@ def test_ignores_irrelevant_warehouse():
31
31
warehouse = Warehouse ({'sku2' : 1000 })
32
32
shipment = Shipment ({'sku1' : 1000 }, eta = tomorrow )
33
33
34
- order . allocate (warehouse = warehouse , shipments = [shipment ])
34
+ allocation = allocate (order , warehouse = warehouse , shipments = [shipment ])
35
35
36
- assert order . allocation ['sku1' ] == shipment
36
+ assert allocation ['sku1' ] == shipment
37
37
38
38
39
39
@@ -42,19 +42,19 @@ def test_can_allocate_to_correct_shipment():
42
42
shipment1 = Shipment ({'sku1' : 1000 }, eta = tomorrow )
43
43
shipment2 = Shipment ({'sku2' : 1000 }, eta = tomorrow )
44
44
45
- order . allocate (warehouse = Warehouse ({}), shipments = [shipment1 , shipment2 ])
45
+ allocation = allocate (order , warehouse = Warehouse ({}), shipments = [shipment1 , shipment2 ])
46
46
47
- assert order . allocation ['sku2' ] == shipment2
47
+ assert allocation ['sku2' ] == shipment2
48
48
49
49
50
50
def test_allocates_to_warehouse_in_preference_to_shipment ():
51
51
order = Order ({'sku1' : 10 })
52
52
warehouse = Warehouse ({'sku1' : 1000 })
53
53
shipment = Shipment ({'sku1' : 1000 }, eta = tomorrow )
54
54
55
- order . allocate (warehouse , shipments = [shipment ])
55
+ allocation = allocate (order , warehouse , shipments = [shipment ])
56
56
57
- assert order . allocation ['sku1' ] == warehouse
57
+ assert allocation ['sku1' ] == warehouse
58
58
assert warehouse ['sku1' ] == 990
59
59
assert shipment ['sku1' ] == 1000
60
60
@@ -63,9 +63,9 @@ def test_can_allocate_multiple_lines_to_wh():
63
63
order = Order ({'sku1' : 5 , 'sku2' : 10 })
64
64
warehouse = Warehouse ({'sku1' : 1000 , 'sku2' : 1000 })
65
65
66
- order . allocate (warehouse , shipments = [])
67
- assert order . allocation ['sku1' ] == warehouse
68
- assert order . allocation ['sku2' ] == warehouse
66
+ allocation = allocate (order , warehouse , shipments = [])
67
+ assert allocation ['sku1' ] == warehouse
68
+ assert allocation ['sku2' ] == warehouse
69
69
assert warehouse ['sku1' ] == 995
70
70
assert warehouse ['sku2' ] == 990
71
71
@@ -74,10 +74,10 @@ def test_can_allocate_multiple_lines_to_shipment():
74
74
order = Order ({'sku1' : 5 , 'sku2' : 10 })
75
75
shipment = Shipment ({'sku1' : 1000 , 'sku2' : 1000 }, eta = tomorrow )
76
76
77
- order . allocate (warehouse = Warehouse ({}), shipments = [shipment ])
77
+ allocation = allocate (order , warehouse = Warehouse ({}), shipments = [shipment ])
78
78
79
- assert order . allocation ['sku1' ] == shipment
80
- assert order . allocation ['sku2' ] == shipment
79
+ assert allocation ['sku1' ] == shipment
80
+ assert allocation ['sku2' ] == shipment
81
81
assert shipment ['sku1' ] == 995
82
82
assert shipment ['sku2' ] == 990
83
83
@@ -87,10 +87,10 @@ def test_can_allocate_to_both():
87
87
shipment = Shipment ({'sku2' : 1000 }, eta = tomorrow )
88
88
warehouse = Warehouse ({'sku1' : 1000 })
89
89
90
- order . allocate (warehouse , shipments = [shipment ])
90
+ allocation = allocate (order , warehouse , shipments = [shipment ])
91
91
92
- assert order . allocation ['sku1' ] == warehouse
93
- assert order . allocation ['sku2' ] == shipment
92
+ assert allocation ['sku1' ] == warehouse
93
+ assert allocation ['sku2' ] == shipment
94
94
assert warehouse ['sku1' ] == 995
95
95
assert shipment ['sku2' ] == 990
96
96
@@ -100,12 +100,12 @@ def test_can_allocate_to_both_preferring_warehouse():
100
100
shipment = Shipment ({'sku1' : 1000 , 'sku2' : 1000 , 'sku3' : 1000 }, eta = tomorrow )
101
101
warehouse = Warehouse ({'sku3' : 1000 , 'sku4' : 1000 })
102
102
103
- order . allocate (warehouse , shipments = [shipment ])
103
+ allocation = allocate (order , warehouse , shipments = [shipment ])
104
104
105
- assert order . allocation ['sku1' ] == shipment
106
- assert order . allocation ['sku2' ] == shipment
107
- assert order . allocation ['sku3' ] == warehouse
108
- assert order . allocation ['sku4' ] == warehouse
105
+ assert allocation ['sku1' ] == shipment
106
+ assert allocation ['sku2' ] == shipment
107
+ assert allocation ['sku3' ] == warehouse
108
+ assert allocation ['sku4' ] == warehouse
109
109
assert shipment ['sku1' ] == 999
110
110
assert shipment ['sku2' ] == 998
111
111
assert shipment ['sku3' ] == 1000
@@ -119,10 +119,10 @@ def test_allocated_to_earliest_suitable_shipment_in_list():
119
119
shipment2 = Shipment ({'sku1' : 1000 , 'sku2' : 1000 }, eta = tomorrow )
120
120
warehouse = Warehouse ({})
121
121
122
- order . allocate (warehouse , shipments = [shipment1 , shipment2 ])
122
+ allocation = allocate (order , warehouse , shipments = [shipment1 , shipment2 ])
123
123
124
- assert order . allocation ['sku1' ] == shipment1
125
- assert order . allocation ['sku2' ] == shipment1
124
+ assert allocation ['sku1' ] == shipment1
125
+ assert allocation ['sku2' ] == shipment1
126
126
127
127
128
128
def test_still_chooses_earliest_if_split_across_shipments ():
@@ -132,11 +132,11 @@ def test_still_chooses_earliest_if_split_across_shipments():
132
132
shipment3 = Shipment ({'sku2' : 1000 , 'sku3' : 1000 }, eta = later )
133
133
warehouse = Warehouse ({})
134
134
135
- order . allocate (warehouse , shipments = [shipment2 , shipment3 , shipment1 ])
135
+ allocation = allocate (order , warehouse , shipments = [shipment2 , shipment3 , shipment1 ])
136
136
137
- assert order . allocation ['sku1' ] == shipment1
138
- assert order . allocation ['sku2' ] == shipment2
139
- assert order . allocation ['sku3' ] == shipment2
137
+ assert allocation ['sku1' ] == shipment1
138
+ assert allocation ['sku2' ] == shipment2
139
+ assert allocation ['sku3' ] == shipment2
140
140
141
141
142
142
def test_warehouse_not_quite_enough_means_we_use_shipment ():
@@ -147,26 +147,26 @@ def test_warehouse_not_quite_enough_means_we_use_shipment():
147
147
'sku2' : 1000 ,
148
148
}, eta = tomorrow )
149
149
150
- order . allocate (warehouse , shipments = [shipment ])
150
+ allocation = allocate (order , warehouse , shipments = [shipment ])
151
151
152
- assert order . allocation ['sku1' ] == shipment
153
- assert order . allocation ['sku2' ] == shipment
152
+ assert allocation ['sku1' ] == shipment
153
+ assert allocation ['sku2' ] == shipment
154
154
155
155
156
156
def test_cannot_allocate_if_insufficent_quantity_in_warehouse ():
157
157
order = Order ({'a-sku' : 10 })
158
158
warehouse = Warehouse ({'a-sku' : 5 })
159
159
160
- order . allocate (warehouse , shipments = [])
160
+ allocation = allocate (order , warehouse , shipments = [])
161
161
162
- assert 'a-sku' not in order . allocation
162
+ assert 'a-sku' not in allocation
163
163
164
164
165
165
def test_cannot_allocate_if_insufficent_quantity_in_shipment ():
166
166
order = Order ({'a-sku' : 10 })
167
167
shipment = Shipment ({'a-sku' : 5 }, eta = tomorrow )
168
168
169
- order . allocate (warehouse = Warehouse ({}), shipments = [shipment ])
169
+ allocation = allocate (order , warehouse = Warehouse ({}), shipments = [shipment ])
170
170
171
- assert 'a-sku' not in order . allocation
171
+ assert 'a-sku' not in allocation
172
172
0 commit comments