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'
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
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
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
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
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)