Last active
September 13, 2022 15:40
-
-
Save mohammadali66/e026dc4dd54776d9a104a2f3057d7f3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_batch_and_line(sku, batch_qty, line_qty): | |
return ( | |
Batch('batch-001', sku, batch_qty, eta=date.today()), | |
OrderLine('order-123', sku, line_qty) | |
) | |
def test_can_allocate_if_available_greater_than_required(): | |
large_batch, small_line = make_batch_and_line("ELEGANT-LAMP", 20, 2) | |
assert large_batch.can_allocate(small_line) | |
def test_cannot_allocate_if_available_smaller_than_required(): | |
small_batch, large_line = make_batch_and_line("ELEGANT-LAMP", 2, 20) | |
assert small_batch.can_allocate(large_line) is False | |
def test_can_allocate_if_available_equal_to_required(): | |
batch, line = make_batch_and_line("ELEGANT-LAMP", 2, 2) | |
assert batch.can_allocate(line) | |
def test_cannot_allocate_if_skus_do_not_match(): | |
batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 100, eta=None) | |
different_sku_line = OrderLine("order-123", "EXPENSIVE-TOASTER", 10) | |
assert batch.can_allocate(different_sku_line) is False | |
def test_can_only_deallocate_allocated_lines(): | |
batch, unallocated_line = make_batch_and_line("DECORATIVE-TRINKET", 20, 2) | |
batch.deallocate(unallocated_line) | |
assert batch.available_quantity == 20 | |
def test_allocation_is_idempotent(): | |
batch, line = make_batch_and_line("ANGULAR-DESK", 20, 2) | |
batch.allocate(line) | |
batch.allocate(line) | |
assert batch.available_quantity == 18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment