@@ -23,6 +23,7 @@ def test_can_allocate_to_stock():
2323 allocate (order , stock , shipments = [])
2424
2525 assert order [0 ].allocation == 'STOCK'
26+ assert stock [0 ].quantity == 990
2627
2728
2829def test_can_allocate_to_shipment ():
@@ -34,6 +35,7 @@ def test_can_allocate_to_shipment():
3435 allocate (order , stock = [], shipments = [shipment ])
3536
3637 assert order [0 ].allocation == shipment .id
38+ assert shipment [0 ].quantity == 990
3739
3840
3941def test_ignores_invalid_stock ():
@@ -46,6 +48,8 @@ def test_ignores_invalid_stock():
4648 allocate (order , stock = stock , shipments = [shipment ])
4749
4850 assert order [0 ].allocation == shipment .id
51+ assert stock [0 ].quantity == 1000
52+ assert shipment [0 ].quantity == 990
4953
5054
5155def test_can_allocate_to_correct_shipment ():
@@ -60,6 +64,8 @@ def test_can_allocate_to_correct_shipment():
6064 allocate (order , stock = [], shipments = [shipment1 , shipment2 ])
6165
6266 assert order [0 ].allocation == shipment2 .id
67+ assert shipment1 [0 ].quantity == 1000
68+ assert shipment2 [0 ].quantity == 990
6369
6470
6571def test_allocates_to_stock_in_preference_to_shipment ():
@@ -73,11 +79,13 @@ def test_allocates_to_stock_in_preference_to_shipment():
7379 allocate (order , stock , shipments = [shipment ])
7480
7581 assert order [0 ].allocation == 'STOCK'
82+ assert stock [0 ].quantity == 990
83+ assert shipment [0 ].quantity == 1000
7684
7785
7886def test_can_allocate_multiple_lines_to_wh ():
7987 order = [
80- OrderLine (sku = 'sku1' , quantity = 10 ),
88+ OrderLine (sku = 'sku1' , quantity = 5 ),
8189 OrderLine (sku = 'sku2' , quantity = 10 ),
8290 ]
8391 stock = [
@@ -88,11 +96,13 @@ def test_can_allocate_multiple_lines_to_wh():
8896 allocate (order , stock , shipments = [])
8997 assert order [0 ].allocation == 'STOCK'
9098 assert order [1 ].allocation == 'STOCK'
99+ assert stock [0 ].quantity == 995
100+ assert stock [1 ].quantity == 990
91101
92102
93103def test_can_allocate_multiple_lines_to_shipment ():
94104 order = [
95- OrderLine (sku = 'sku1' , quantity = 10 ),
105+ OrderLine (sku = 'sku1' , quantity = 5 ),
96106 OrderLine (sku = 'sku2' , quantity = 10 ),
97107 ]
98108 shipment = Shipment ('shipment1' , eta = date .today (), lines = [
@@ -104,11 +114,13 @@ def test_can_allocate_multiple_lines_to_shipment():
104114
105115 assert order [0 ].allocation == shipment .id
106116 assert order [1 ].allocation == shipment .id
117+ assert shipment [0 ].quantity == 995
118+ assert shipment [1 ].quantity == 990
107119
108120
109121def test_can_allocate_to_both ():
110122 order = [
111- OrderLine (sku = 'sku1' , quantity = 10 ),
123+ OrderLine (sku = 'sku1' , quantity = 5 ),
112124 OrderLine (sku = 'sku2' , quantity = 10 ),
113125 ]
114126 shipment = Shipment ('shipment1' , eta = date .today (), lines = [
@@ -120,14 +132,16 @@ def test_can_allocate_to_both():
120132
121133 assert order [0 ].allocation == 'STOCK'
122134 assert order [1 ].allocation == shipment .id
135+ assert stock [0 ].quantity == 995
136+ assert shipment [0 ].quantity == 990
123137
124138
125139def test_can_allocate_to_both_preferring_stock ():
126140 order = [
127- OrderLine (sku = 'sku1' , quantity = 10 ),
128- OrderLine (sku = 'sku2' , quantity = 10 ),
129- OrderLine (sku = 'sku3' , quantity = 10 ),
130- OrderLine (sku = 'sku4' , quantity = 10 ),
141+ OrderLine (sku = 'sku1' , quantity = 1 ),
142+ OrderLine (sku = 'sku2' , quantity = 2 ),
143+ OrderLine (sku = 'sku3' , quantity = 3 ),
144+ OrderLine (sku = 'sku4' , quantity = 4 ),
131145 ]
132146 shipment = Shipment ('shipment1' , eta = date .today (), lines = [
133147 Line (sku = 'sku1' , quantity = 1000 ),
@@ -145,6 +159,12 @@ def test_can_allocate_to_both_preferring_stock():
145159 assert order [1 ].allocation == shipment .id
146160 assert order [2 ].allocation == 'STOCK'
147161 assert order [3 ].allocation == 'STOCK'
162+ assert shipment [0 ].quantity == 999
163+ assert shipment [1 ].quantity == 998
164+ assert shipment [2 ].quantity == 1000
165+ assert shipment [3 ].quantity == 1000
166+ assert stock [0 ].quantity == 997
167+ assert stock [1 ].quantity == 996
148168
149169
150170def test_mixed_allocations_are_avoided_if_possible ():
@@ -233,7 +253,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
233253 assert order [0 ].allocation is None
234254
235255
236- def test_allocation_decreases_quantity_available_on_shipments ():
256+ def test_cannot_allocate_more_orders_than_we_have_stock_for ():
237257 order1 = [OrderLine (sku = 'a-sku' , quantity = 10 )]
238258 order2 = [OrderLine (sku = 'a-sku' , quantity = 10 )]
239259 stock = [Line (sku = 'a-sku' , quantity = 15 )]
0 commit comments