Skip to content

Commit 92a67f4

Browse files
committed
fix a few remaining places where stock was a list
1 parent dd060c5 commit 92a67f4

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

domain_model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ def __init__(self, id, eta, lines):
55
super().__init__(lines)
66

77

8-
def skus(thing):
9-
try:
10-
return {line.sku for line in thing}
11-
except:
12-
return thing.keys()
8+
def skus(d):
9+
return d.keys()
1310

1411

1512
def allocate_line(sku, quantity, source, allocations):
1613
if source.get(sku, 0) > quantity:
1714
source[sku] -= quantity
1815
allocations[sku] = getattr(source, 'id', 'STOCK')
1916

17+
2018
def allocate_to(order, source):
2119
allocations = {}
2220
for sku, quantity in order.items():

test_allocation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_can_allocate_to_shipment():
2828
'a-sku': 1000
2929
})
3030

31-
allocations = allocate(order, stock=[], shipments=[shipment])
31+
allocations = allocate(order, stock={}, shipments=[shipment])
3232

3333
assert allocations['a-sku'] == shipment.id
3434
assert shipment['a-sku'] == 990
@@ -57,7 +57,7 @@ def test_can_allocate_to_correct_shipment():
5757
'sku2': 1000,
5858
})
5959

60-
allocations = allocate(order, stock=[], shipments=[shipment1, shipment2])
60+
allocations = allocate(order, stock={}, shipments=[shipment1, shipment2])
6161

6262
assert allocations['sku2'] == shipment2.id
6363
assert shipment1['sku1'] == 1000
@@ -96,7 +96,7 @@ def test_can_allocate_multiple_lines_to_shipment():
9696
'sku2': 1000,
9797
})
9898

99-
allocations = allocate(order, [], shipments=[shipment])
99+
allocations = allocate(order, stock={}, shipments=[shipment])
100100

101101
assert allocations['sku1'] == shipment.id
102102
assert allocations['sku2'] == shipment.id
@@ -213,7 +213,7 @@ def test_cannot_allocate_if_insufficent_quantity_in_shipment():
213213
'a-sku': 5,
214214
})
215215

216-
allocations = allocate(order, stock=[], shipments=[shipment])
216+
allocations = allocate(order, stock={}, shipments=[shipment])
217217

218218
assert 'a-sku' not in allocations
219219

0 commit comments

Comments
 (0)