Пример #1
0
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
Пример #2
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)

    line = OrderLine('oref1', 'MINIMALIST-SPOON', 10)
    allocate(line, [earliest, medium, latest])
    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
Пример #3
0
def test_prefers_warehouse_batches_to_shipments():
    sku = 'RETRO-CLOCK'
    in_stock_batch = 'in-stock-batch'
    shipment_batch = 'shipment-batch'

    uow = FakeUnitOfWork(None)
    handlers.add_batch(in_stock_batch, sku, 100, None, uow)
    handlers.add_batch(shipment_batch, sku, 100, tomorrow, uow)

    handlers.allocate('oref', sku, 10, uow)
    product = uow.products.get(sku=sku)
    assert product.get_batch(in_stock_batch).available_quantity == 90
    assert product.get_batch(shipment_batch).available_quantity == 100
Пример #4
0
def test_allocate_returns_allocation():
    uow = FakeUnitOfWork(
        FakeProductRepository.for_batch('b1', 'COMPLICATED-LAMP', 100, eta=None))
    handlers.add_batch('b1', 'COMPLICATED-LAMP', 100, None, uow)

    result = handlers.allocate('o1', 'COMPLICATED-LAMP', 10, uow)
    assert result == 'b1'
Пример #5
0
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)

    line = OrderLine('oref', 'HIGHBROW-POSTER', 10)
    allocation = allocate(line, [in_stock_batch, shipment_batch])
    assert allocation == in_stock_batch.reference
    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Пример #6
0
def test_records_out_of_stock_event_if_cannot_allocate():
    sku = 'RETRO-CLOCK'
    in_stock_batch = 'in-stock-batch'

    uow = FakeUnitOfWork(None)
    handlers.add_batch(in_stock_batch, sku, 10, None, uow)

    allocation = handlers.allocate('oref', sku, 11, uow)
    product = uow.products.get(sku=sku)

    # assert product.events[-1] == events.OutOfStock(sku=sku)
    assert allocation is None
Пример #7
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    allocate(OrderLine('order1', 'SMALL-FORK', 10), [batch])
    with pytest.raises(OutOfStock, match='SMALL-FORK'):
        allocate(OrderLine('order2', 'SMALL-FORK', 1), [batch])
Пример #8
0
def test_commits():
    uow = FakeUnitOfWork(None)
    handlers.add_batch('b1', 'OMINOUS-MIRROR', 100, None, uow)

    handlers.allocate('o1', 'OMINOUS-MIRROR', 10, uow)
    assert uow.committed is True
Пример #9
0
def test_error_for_invalid_sku():
    uow = FakeUnitOfWork(None)
    handlers.add_batch('b1', 'AREALSKU', 100, None, uow)

    with pytest.raises(handlers.InvalidSku, match='Invalid sku NONEXISTENTSKU'):
        handlers.allocate('o1', 'NONEXISTENTSKU', 10, uow)