Beispiel #1
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine('order1', 'SMALL-FORK', 10))

    with pytest.raises(OutOfStock, match='SMALL-FORK'):
        product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
Beispiel #2
0
def test_increments_version_number():
    line = OrderLine('oref', "SCANDI-PEN", 10)
    product = Product(sku="SCANDI-PEN",
                      batches=[Batch('b1', "SCANDI-PEN", 100, eta=None)])
    product.version_number = 7
    product.allocate(line)
    assert product.version_number == 8
Beispiel #3
0
def test_records_out_of_stock_event_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine('order1', 'SMALL-FORK', 10))

    allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
    assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
    assert allocation is None
Beispiel #4
0
def test_outputs_allocated_event():
    batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
    line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
    product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
    product.allocate(line)
    expected = events.Allocated(
        orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
    )
    assert product.events[-1] == expected
def test_prefers_warehouse_batches_to_shipments():
    in_stock_batch = Batch("batch-001", "BIG-SOFA", qty=20, eta=None)
    shipment_batch = Batch("batch-002", "BIG-SOFA", qty=20, eta=today)
    product = Product(sku="BIG-SOFA", batches=[in_stock_batch, shipment_batch])
    line = OrderLine("order-123", "BIG-SOFA", 5)

    product.allocate(line)

    assert in_stock_batch.available_quantity == 15
    assert shipment_batch.available_quantity == 20
Beispiel #6
0
def test_prefers_warehouse_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)
    product = Product(sku="RETRO-CLOCK", batches=[in_stock_batch, shipment_batch])
    line = OrderLine("oref", "RETRO-CLOCK", 10)

    product.allocate(line)

    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Beispiel #7
0
def test_allocation_emmits_events():
    sku = "KALANCHOE-EVENTO"
    batch = BatchOrder("b1", sku, 100, eta=TOMORROW)
    product = Product(sku, batches=[batch])
    line = OrderLine("o1", sku, qty=85)

    product.add_batch(batch)
    product.allocate(line)

    assert type(product.latest_event) == events.Allocated
Beispiel #8
0
def test_records_out_of_stock_event_if_cannot_allocate():
    sku = "KALANCHOE-EVENTO"
    batch = BatchOrder("b1", sku, 15, eta=TOMORROW)
    product = Product(sku, batches=[batch])

    product.allocate(OrderLine("o1", sku, 10))
    b2 = product.allocate(OrderLine("o2", sku, 20))

    assert product.latest_event == events.OutOfStock(sku=sku)
    assert b2 is None
Beispiel #9
0
def test_version_number_increments() -> None:
    sku = "KALANCHOE-P11"
    batch_today = BatchOrder("shipment-ref02", sku, 100, eta=date.today())
    line = OrderLine("o-ref", sku, 10)

    product = Product(sku, [batch_today])
    assert product.version_number == 0
    product.allocate(line)
    assert product.version_number == 1
    product.deallocate()
    assert product.version_number == 2
Beispiel #10
0
def test_prefers_current_stock_batches_to_shipments() -> None:
    sku = "KALANCHOE-P11"
    batch_in_stock = BatchOrder("in-stock-ref", sku, 100, eta=None)
    batch_shipment = BatchOrder("shipment-ref", sku, 100, eta=TOMORROW)
    line = OrderLine("o-ref", sku, 10)
    product = Product(sku, [batch_in_stock, batch_shipment])

    product.allocate(line)

    assert batch_in_stock.available_quantity == 90
    assert batch_shipment.available_quantity == 100
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch("batch-001", "SMALL-TABLE", qty=5, eta=today)
    line1 = OrderLine("order-1", "SMALL-TABLE", 5)
    line2 = OrderLine("order-2", "SMALL-TABLE", 5)

    product = Product(sku="SMALL-TABLE", batches=[batch])
    product.allocate(line1)

    allocation = product.allocate(line2)
    assert product.events[-1] == OutOfStock(sku="SMALL-TABLE")
    assert allocation is None
Beispiel #12
0
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)
    product = Product(sku="MINIMALIST-SPOON", batches=[medium, earliest, latest])
    line = OrderLine("order1", "MINIMALIST-SPOON", 10)

    product.allocate(line)

    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
Beispiel #13
0
def test_prefer_earlier_batches() -> None:
    sku = "KALANCHOE-P11"
    batch_today = BatchOrder("shipment-ref02", sku, 100, eta=date.today())
    batch_yesterday = BatchOrder("shipment-ref03", sku, 100, eta=YESTERDAY)
    batch_tomorrow = BatchOrder("shipment-ref04", sku, 100, eta=TOMORROW)
    line = OrderLine("o-ref", sku, 10)

    product = Product(sku, [batch_today, batch_yesterday, batch_tomorrow])
    product.allocate(line)

    assert batch_yesterday.available_quantity == 90
    assert batch_today.available_quantity == 100
    assert batch_tomorrow.available_quantity == 100
Beispiel #14
0
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)
    product = Product(sku="HIGHBROW-POSTER", batches=[in_stock_batch, shipment_batch])
    allocation = product.allocate(line)
    assert allocation == in_stock_batch.reference
def test_returns_allocated_batch_reference():
    in_stock_batch = Batch("batch-001", "BIG-SOFA", qty=20, eta=None)
    shipment_batch = Batch("batch-002", "BIG-SOFA", qty=20, eta=today)
    product = Product(sku="BIG-SOFA", batches=[in_stock_batch, shipment_batch])
    line = OrderLine("order-123", "BIG-SOFA", 5)

    allocation = product.allocate(line)

    assert allocation == in_stock_batch.reference
def test_prefers_earlier_batches():
    tomorrows_batch = Batch("batch-001", "MINI-SPOON", qty=20, eta=tomorrow)
    upcoming_batch = Batch("batch-001", "MINI-SPOON", qty=20, eta=later)
    product = Product(sku="MINI-SPOON",
                      batches=[tomorrows_batch, upcoming_batch])
    line = OrderLine("order-123", "MINI-SPOON", 5)

    allocation = product.allocate(line)

    assert allocation == tomorrows_batch.reference
    assert tomorrows_batch.available_quantity == 15
    assert upcoming_batch.available_quantity == 20
def test_returns_allocated_batch_ref():
    in_stock_batch = Batch('in-stock-batch', 'HIGHBROW-POSTER', 100, eta=None)
    shipment_batch = Batch('shipment-batch',
                           'HIGHBROW-POSTER',
                           100,
                           eta=tomorrow)
    product = Product(sku='HIGHBROW-POSTER',
                      batches=[in_stock_batch, shipment_batch])
    line = OrderLine('oref', 'HIGHBROW-POSTER', 10)

    allocation = product.allocate(line)
    assert allocation == in_stock_batch.reference
Beispiel #18
0
def test_outputs_allocated_event():
    batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
    line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
    product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
    product.allocate(line)
    expected = events.Allocated(
        orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
    )
    assert product.events[-1] == expected


def test_records_out_of_stock_event_if_cannot_allocate():
<<<<<<< HEAD
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine('order1', 'SMALL-FORK', 10))

    allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
=======
    batch = Batch("batch1", "SMALL-FORK", 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine("order1", "SMALL-FORK", 10))

    allocation = product.allocate(OrderLine("order2", "SMALL-FORK", 1))
>>>>>>> upstream/master
    assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
    assert allocation is None


def test_increments_version_number():
<<<<<<< HEAD