Example #1
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'
Example #2
0
def test_add_batch():
    batch = 'b1'
    sku = 'CRUNCHY-ARMCHAIR'

    uow = FakeUnitOfWork(None)
    handlers.add_batch(batch, sku, 100, None, uow)
    assert uow.products.get(sku=sku).get_batch(batch) is not None
    assert uow.committed
Example #3
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
Example #4
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
Example #5
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
Example #6
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)