Пример #1
0
def test_error_for_invalid_sku():
    line = model.OrderLine("o1", "NONEXISTENTSKU", 10)
    batch = model.Batch("b1", "AREALSKU", 100, eta=None)
    repo = FakeRepository([batch])

    with pytest.raises(handlers.InvalidSku, match="Invalid name of SKU: NONEXISTENTSKU"):
        handlers.allocate("o1", "NONEXISTENTSKU", 10, repo, FakeSession())
Пример #2
0
def test_commits():
    line = model.OrderLine("o1", "OMINOUS-MIRROR", 10)
    batch = model.Batch("b1", "OMINOUS-MIRROR", 100, eta=None)
    repo = FakeRepository([batch])
    session = FakeSession()

    handlers.allocate("o1", "OMINOUS-MIRROR", 10, repo, session)
    assert session.committed is True
Пример #3
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)
    repo = FakeRepository([in_stock_batch, shipment_batch])
    session = FakeSession()

    line = OrderLine('oref', "RETRO-CLOCK", 10)
    handlers.allocate(line, repo, session)

    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Пример #4
0
 def test_returns_allocation(self):
     uow = FakeUnitOfWork()
     handlers.add_batch("b1", "COMPLICATED-LAMP", 100, None, uow)
     results = handlers.allocate("o1", "COMPLICATED-LAMP", 100, None, uow)
     messagebus.handle(
         events.BatchCreated("batch1", "COMPLICATED-LAMP", 100, None), uow)
     result = messagebus.handle(
         events.AllocationRequired("o1", "COMPLICATED-LAMP", 10), uow)
     assert result == "batch1"
Пример #5
0
def test_allocate_returns_allocation():
    uow = FakeUnitOfWork()
    handlers.add_batch("batch1", "COMPLICATED-LAMP", 100, None, uow)
    result = handlers.allocate("o1", "COMPLICATED-LAMP", 10, uow)
    assert result == "bach1"