Skip to content

Commit d1dda70

Browse files
committed
new tests for allocate domain service [test_allocate]
1 parent 235e121 commit d1dda70

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test_allocate.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from datetime import date, timedelta
2+
from model import allocate, OrderLine, Batch
3+
4+
today = date.today()
5+
tomorrow = today + timedelta(days=1)
6+
later = tomorrow + timedelta(days=10)
7+
8+
9+
def test_prefers_current_stock_batches_to_shipments():
10+
in_stock_batch = Batch("in-warehouse-stock", "RETRO-CLOCK", 100, eta=None)
11+
shipment_batch = Batch("shipment-batch", "RETRO-CLOCK", 100, eta=tomorrow)
12+
line = OrderLine("oref", "RETRO-CLOCK", 10)
13+
14+
allocate(line, [in_stock_batch, shipment_batch])
15+
16+
assert in_stock_batch.available_quantity == 90
17+
assert shipment_batch.available_quantity == 100
18+
19+
20+
def test_prefers_earlier_batches():
21+
earliest = Batch("speedy-batch", "MINIMALIST-SPOON", 100, eta=today)
22+
medium = Batch("normal-batch", "MINIMALIST-SPOON", 100, eta=tomorrow)
23+
latest = Batch("slow-batch", "MINIMALIST-SPOON", 100, eta=later)
24+
line = OrderLine("order1", "MINIMALIST-SPOON", 10)
25+
26+
allocate(line, [medium, earliest, latest])
27+
28+
assert earliest.available_quantity == 90
29+
assert medium.available_quantity == 100
30+
assert latest.available_quantity == 100

0 commit comments

Comments
 (0)