示例#1
0
def test_allocate_errors_for_invalid_sku():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "AREALSKU", 100, None, uow)

    with pytest.raises(services.InvalidSku,
                       match="Invalid sku NONEXISTENTSKU"):
        services.allocate("o1", "NONEXISTENTSKU", 10, uow)
示例#2
0
def test_add_batch_for_existing_product():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "GARISH-RUG", 100, None, uow)
    services.add_batch("b2", "GARISH-RUG", 99, None, uow)
    assert "b2" in [
        b.reference for b in uow.products.get("GARISH-RUG").batches
    ]
示例#3
0
def add_batch():
    uow = unit_of_work.SqlAlchemyUnitOfWork()
    eta = request.json['eta']
    if eta is not None:
        eta = datetime.fromisoformat(eta).date()
    services.add_batch(request.json['ref'], request.json['sku'],
                       request.json['qty'], eta, uow)
    return 'OK', 201
示例#4
0
def test_error_for_not_allocated_line():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "AREALSKU", 100, None, uow)

    with pytest.raises(NotAllocatedOrder,
                       match=f"Given order hasn't been allocated"
                       f" o1"):
        services.deallocate("o1", 'AREALSKU', 10, uow)
示例#5
0
def add_batch():
    session = get_session()
    repo = repository.SqlAlchemyRepository(session)
    eta = request.json['eta']
    if eta is not None:
        eta = datetime.fromisoformat(eta).date()
    services.add_batch(request.json['ref'], request.json['sku'],
                       request.json['qty'], eta, repo, session)
示例#6
0
def test_deallocate_decrements_available_quantity():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "BLUE-PLINTH", 100, None, uow)
    services.allocate('o1', 'BLUE-PLINTH', 10, uow)
    batch = uow.batches.get(sku="BLUE-PLINTH")
    assert batch.available_quantity == 90

    services.deallocate('o1', 'BLUE-PLINTH', 10, uow)
    batch = uow.batches.get(sku='BLUE-PLINTH')
    assert batch.available_quantity == 100
示例#7
0
def test_commits():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow)
    services.allocate("o1", "OMINOUS-MIRROR", 10, uow)
    assert uow.committed
示例#8
0
def test_allocate_returns_allocation():
    uow = FakeUnitOfWork()
    services.add_batch("batch1", "COMPLICATED-LAMP", 100, None, uow)
    result = services.allocate("o1", "COMPLICATED-LAMP", 10, uow)
    assert result == "batch1"
示例#9
0
def test_add_batch_for_new_product():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, uow)
    assert uow.products.get("CRUNCHY-ARMCHAIR")
    assert uow.committed
示例#10
0
def test_error_for_invalid_sku():
    uow = FakeUnitOfWork()
    services.add_batch("batch", "EXISTINGSKU", 100, None, uow)
    with pytest.raises(services.InvalidSku,
                       match="Invalid sku NONEXISTINGSKU"):
        services.allocate("o1", 'NONEXISTINGSKU', 10, uow)