예제 #1
0
def test_cannot_allocate_if_skus_do_not_match():
    # given
    batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", qty=100, eta=None)
    different_sku_line = OrderLine("order123", "EXPENSIVE-TOASTER", qty=10)

    # then
    assert batch.can_allocate(different_sku_line) is False
예제 #2
0
def test_prefers_current_stock_batches_to_shipments():
    # given
    in_stock_batch = Batch("in-stock-batch", "RETRO-CLOCK", 100, eta=None)
    shipment_batch = Batch("in-stock-batch", "RETRO-CLOCK", 100, eta=tomorrow)
    line = OrderLine("oref", "RETRO-CLOCK", 10)

    # when
    allocate(line, [in_stock_batch, shipment_batch])

    # then
    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
예제 #3
0
def test_prefers_earlier_batches():
    # given
    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)

    # when
    allocate(line, [medium, earliest, latest])

    # then
    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
예제 #4
0
def test_returns_allocated_batch_ref():
    in_stock_batch = Batch("in-stock-batch-ref",
                           "HIGHBROW-POSTER",
                           100,
                           eta=None)
    shipment_batch = Batch("in-stock-batch-ref",
                           "HIGHBROW-POSTER",
                           100,
                           eta=tomorrow)
    line = OrderLine("oref", "HIGHBROW-POSTER", 10)

    # when
    allocation = allocate(line, [in_stock_batch, shipment_batch])

    # then
    assert allocation == in_stock_batch.reference
예제 #5
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    # given
    batch = Batch("batch1", "SMALL-FORK", 10, eta=today)
    allocate(OrderLine("order1", "SMALL-FORK", 10), [batch])

    # when / then
    with pytest.raises(OutOfStock, match="SMALL-FORK"):
        allocate(OrderLine("order2", "SMALL-FORK", 1), [batch])
예제 #6
0
def test_batch_hash():
    # given
    reference = "order174"
    batch = Batch(ref=reference, sku="LOUD-STEREO", qty=19, eta=date.today())

    # when
    actual = hash(batch)

    # then
    assert actual == hash(reference)
예제 #7
0
def make_batch_and_line(sku: str, batch_qty: int, line_qty: int):
    return (
        Batch("batch-001", sku, qty=batch_qty, eta=date.today()),
        OrderLine("order123", sku, qty=line_qty),
    )