Created
September 17, 2022 19:12
-
-
Save mohammadali66/7ee4796dd0c4878e071d656cf4bdfb4b 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 test_prefers_current_stock_batches_to_shipments(): | |
in_stock_batch = Batch("in-stock-batch", "RETRO-CLOCK", 100, eta=None) | |
shipment_batch = Batch("shipment-batch", "RETRO-CLOCK", 100, eta=tomorrow) | |
line = OrderLine("oref", "RETRO-CLOCK", 10) | |
allocate(line, [in_stock_batch, shipment_batch]) | |
assert in_stock_batch.available_quantity == 90 | |
assert shipment_batch.available_quantity == 100 | |
def test_prefers_earlier_batches(): | |
earliest = Batch("speedy-batch", "MINIMALIST-SPOON", 100, eta=today) | |
medium = Batch("normal-batch", "MINIMALIST-SPOON", 100, eta=tomorrow) | |
latest = Batch("slow-batch", "MINIMALIST-SPOON", 100, eta=later) | |
line = OrderLine("order1", "MINIMALIST-SPOON", 10) | |
allocate(line, [medium, earliest, latest]) | |
assert earliest.available_quantity == 90 | |
assert medium.available_quantity == 100 | |
assert latest.available_quantity == 100 | |
def test_returns_allocated_batch_ref(): | |
in_stock_batch = Batch("in-stock-batch-ref", "HIGHBROW-POSTER", 100, eta=None) | |
shipment_batch = Batch("shipment-batch-ref", "HIGHBROW-POSTER", 100, eta=tomorrow) | |
line = OrderLine("oref", "HIGHBROW-POSTER", 10) | |
allocation = allocate(line, [in_stock_batch, shipment_batch]) | |
assert allocation == in_stock_batch.referenc | |
def allocate(line: OrderLine, batches: List[Batch]) -> str: | |
batch = next( | |
b for b in sorted(batches) if b.can_allocate(line) | |
) | |
batch.allocate(line) | |
return batch.reference |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment