33
44
55from domain_model import (
6- Allocation ,
76 Order ,
87 OrderLine ,
98 Shipment ,
109 Stock ,
11- allocate as allocate_
10+ allocate ,
1211)
1312
1413
15- allocate = lambda * a , ** kw : list (allocate_ (* a , ** kw ))
1614
1715
1816def random_id ():
@@ -26,12 +24,9 @@ def test_can_allocate_to_warehouse_stock():
2624 ])
2725 stock = Stock (sku = sku , quantity = 1000 )
2826
29- allocations = allocate (order , [stock ], shipments = [])
27+ allocate (order , [stock ], shipments = [])
3028
31- assert allocations [0 ].order_id == order .id
32- assert allocations [0 ].sku == sku
33- assert allocations [0 ].shipment_id is None
34- assert allocations [0 ].quantity == 10
29+ assert order .lines [0 ].allocation == 'warehouse'
3530
3631
3732def test_can_allocate_to_shipment ():
@@ -43,12 +38,9 @@ def test_can_allocate_to_shipment():
4338 OrderLine (sku = sku , quantity = 1000 ),
4439 ])
4540
46- allocations = allocate (order , stock = [], shipments = [shipment ])
41+ allocate (order , stock = [], shipments = [shipment ])
4742
48- assert allocations [0 ].order_id == order .id
49- assert allocations [0 ].sku == sku
50- assert allocations [0 ].shipment_id == shipment .id
51- assert allocations [0 ].quantity == 10
43+ assert order .lines [0 ].allocation == shipment .id
5244
5345
5446def test_ignores_invalid_stock ():
@@ -61,12 +53,9 @@ def test_ignores_invalid_stock():
6153 OrderLine (sku = sku1 , quantity = 1000 ),
6254 ])
6355
64- allocations = allocate (order , stock = [stock ], shipments = [shipment ])
56+ allocate (order , stock = [stock ], shipments = [shipment ])
6557
66- assert allocations [0 ].order_id == order .id
67- assert allocations [0 ].sku == sku1
68- assert allocations [0 ].shipment_id == shipment .id
69- assert allocations [0 ].quantity == 10
58+ assert order .lines [0 ].allocation == shipment .id
7059
7160
7261def test_can_allocate_to_correct_shipment ():
@@ -81,12 +70,9 @@ def test_can_allocate_to_correct_shipment():
8170 OrderLine (sku = sku2 , quantity = 1000 ),
8271 ])
8372
84- allocations = allocate (order , stock = [], shipments = [shipment1 , shipment2 ])
73+ allocate (order , stock = [], shipments = [shipment1 , shipment2 ])
8574
86- assert allocations [0 ].order_id == order .id
87- assert allocations [0 ].sku == sku2
88- assert allocations [0 ].shipment_id == shipment2 .id
89- assert allocations [0 ].quantity == 10
75+ assert order .lines [0 ].allocation == shipment2 .id
9076
9177
9278def test_allocates_to_warehouse_stock_in_preference_to_shipment ():
@@ -99,12 +85,9 @@ def test_allocates_to_warehouse_stock_in_preference_to_shipment():
9985 OrderLine (sku = sku , quantity = 1000 ),
10086 ])
10187
102- allocations = allocate (order , [stock ], shipments = [shipment ])
88+ allocate (order , [stock ], shipments = [shipment ])
10389
104- assert allocations [0 ].order_id == order .id
105- assert allocations [0 ].sku == sku
106- assert allocations [0 ].shipment_id is None
107- assert allocations [0 ].quantity == 10
90+ assert order .lines [0 ].allocation == 'warehouse'
10891
10992
11093def test_can_allocate_multiple_lines_to_wh ():
@@ -118,9 +101,9 @@ def test_can_allocate_multiple_lines_to_wh():
118101 Stock (sku = sku2 , quantity = 1000 ),
119102 ]
120103
121- allocations = allocate (order , stock , shipments = [])
122- assert Allocation ( order .id , sku1 , 10 , shipment_id = None ) in allocations
123- assert Allocation ( order .id , sku2 , 10 , shipment_id = None ) in allocations
104+ allocate (order , stock , shipments = [])
105+ assert order .lines [ 0 ]. allocation == 'warehouse'
106+ assert order .lines [ 1 ]. allocation == 'warehouse'
124107
125108
126109def test_can_allocate_multiple_lines_to_shipment ():
@@ -134,9 +117,10 @@ def test_can_allocate_multiple_lines_to_shipment():
134117 OrderLine (sku = sku2 , quantity = 1000 ),
135118 ])
136119
137- allocations = allocate (order , [], shipments = [shipment ])
138- assert Allocation (order .id , sku1 , 10 , shipment_id = shipment .id ) in allocations
139- assert Allocation (order .id , sku2 , 10 , shipment_id = shipment .id ) in allocations
120+ allocate (order , [], shipments = [shipment ])
121+
122+ assert order .lines [0 ].allocation == shipment .id
123+ assert order .lines [1 ].allocation == shipment .id
140124
141125
142126def test_can_allocate_to_both ():
@@ -152,9 +136,10 @@ def test_can_allocate_to_both():
152136 Stock (sku = sku1 , quantity = 1000 ),
153137 ]
154138
155- allocations = allocate (order , stock , shipments = [shipment ])
156- assert Allocation (order .id , sku1 , 10 , shipment_id = None ) in allocations
157- assert Allocation (order .id , sku2 , 10 , shipment_id = shipment .id ) in allocations
139+ allocate (order , stock , shipments = [shipment ])
140+
141+ assert order .lines [0 ].allocation == 'warehouse'
142+ assert order .lines [1 ].allocation == shipment .id
158143
159144
160145def test_can_allocate_to_both_preferring_stock ():
@@ -175,11 +160,10 @@ def test_can_allocate_to_both_preferring_stock():
175160 Stock (sku = sku4 , quantity = 1000 ),
176161 ]
177162
178- allocations = allocate (order , stock , shipments = [shipment ])
179- assert Allocation (order .id , sku1 , 10 , shipment_id = shipment .id ) in allocations
180- assert Allocation (order .id , sku2 , 10 , shipment_id = shipment .id ) in allocations
181- assert Allocation (order .id , sku3 , 10 , shipment_id = None ) in allocations
182- assert Allocation (order .id , sku4 , 10 , shipment_id = None ) in allocations
183- assert Allocation (order .id , sku3 , 10 , shipment_id = shipment .id ) not in allocations
163+ allocate (order , stock , shipments = [shipment ])
184164
165+ assert order .lines [0 ].allocation == shipment .id
166+ assert order .lines [1 ].allocation == shipment .id
167+ assert order .lines [2 ].allocation == 'warehouse'
168+ assert order .lines [3 ].allocation == 'warehouse'
185169
0 commit comments