Skip to content

Commit 108a74c

Browse files
committed
more tests for can_allocate [test_can_allocate]
1 parent fc5811e commit 108a74c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test_batches.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import date
12
from model import Batch, OrderLine
23
from datetime import date
34

@@ -9,3 +10,27 @@ def test_allocating_to_a_batch_reduces_the_available_quantity():
910
batch.allocate(line)
1011

1112
assert batch.available_quantity == 18
13+
14+
15+
def make_batch_and_line(sku, batch_qty, line_qty):
16+
return (
17+
Batch("batch-001", sku, batch_qty, eta=date.today()),
18+
OrderLine("order-123", sku, line_qty),
19+
)
20+
21+
def test_can_allocate_if_available_greater_than_required():
22+
large_batch, small_line = make_batch_and_line("ELEGANT-LAMP", 20, 2)
23+
assert large_batch.can_allocate(small_line)
24+
25+
def test_cannot_allocate_if_available_smaller_than_required():
26+
small_batch, large_line = make_batch_and_line("ELEGANT-LAMP", 2, 20)
27+
assert small_batch.can_allocate(large_line) is False
28+
29+
def test_can_allocate_if_available_equal_to_required():
30+
batch, line = make_batch_and_line("ELEGANT-LAMP", 2, 2)
31+
assert batch.can_allocate(line)
32+
33+
def test_cannot_allocate_if_skus_do_not_match():
34+
batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 100, eta=None)
35+
different_sku_line = OrderLine("order-123", "EXPENSIVE-TOASTER", 10)
36+
assert batch.can_allocate(different_sku_line) is False

0 commit comments

Comments
 (0)