コード例 #1
0
def test_allocate_error_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 add_batch():
    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,
                       unit_of_work.SqlAlchemyUnitOfWork())
    return 'OK', 201
コード例 #3
0
ファイル: flask_app.py プロジェクト: aikiwi/APwP
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
    )
    return 'OK', 201
コード例 #4
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
コード例 #5
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'
コード例 #6
0
def test_add_batch():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, uow)
    assert uow.batches.get("b1") is not None
    assert uow.committed
コード例 #7
0
def test_commits():
    repo, session = FakeRepository([]), FakeSession()
    session = FakeSession()
    services.add_batch("b1", "OMINOUS-MIRROR", 100, None, repo, session)
    services.allocate("o1", "OMINOUS-MIRROR", 10, repo, session)
    assert session.committed is True
コード例 #8
0
def test_allocate_errors_for_invalid_sku():
    repo, session = FakeRepository([]), FakeSession()
    services.add_batch("b1", "AREALSKU", 100, None, repo, session)

    with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"):
        services.allocate("o1", "NONEXISTENTSKU", 10, repo, FakeSession())
コード例 #9
0
def test_allocate_returns_allocation():
    repo, session = FakeRepository([]), FakeSession()
    services.add_batch("batch1", "COMPLICATED-LAMP", 100, None, repo, session)
    result = services.allocate("o1", "COMPLICATED-LAMP", 10, repo, session)
    assert result == "batch1"
コード例 #10
0
def test_add_batch():
    repo, session = FakeRepository([]), FakeSession()
    services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, repo, session)
    assert repo.get("b1") is not None
    assert session.committed