def test_repository_can_retrieve_a_batch_with_allocations(session):
    orderline_id = insert_order_line(session)
    batch1_id = insert_batch(session, "batch1")
    insert_batch(session, "batch2")
    insert_allocation(session, orderline_id, batch1_id)

    repo = repository.SqlAlchemyRepository(session)
    retrieved = repo.get("batch1")

    expected = model.Batch("batch1", "GENERIC-SOFA", 100, eta=None)
    assert retrieved == expected  # Batch.__eq__ only compares reference
    assert retrieved.sku == expected.sku
    assert retrieved._purchased_quantity == expected._purchased_quantity
    assert retrieved._allocations == {
        model.OrderLine("order1", "GENERIC-SOFA", 12),
    }
Esempio n. 2
0
def test_repository_can_retrieve_a_batch_with_allocations(session):
    orderline_id = insert_order_line(session)
    batch1_id = insert_product_batch(session, "batch1")
    insert_batch(session, "batch2")
    insert_allocation(session, orderline_id, batch1_id)

    repo = repository.SqlAlchemyRepository(session)
    retrieved = repo.get("GENERIC-SOFA")

    batch = model.Batch("batch1", "GENERIC-SOFA", 100, eta=None)
    expected = model.Product("GENERIC-SOFA", [batch])
    assert retrieved == expected
    assert retrieved.batches[
        0]._purchased_quantity == batch._purchased_quantity
    assert retrieved.batches[0]._allocations == {
        model.OrderLine("order1", "GENERIC-SOFA", 12),
    }
Esempio n. 3
0
def test_retrieving_allocations(sqlite_session):
    sqlite_session.execute('INSERT INTO order_lines (orderid, sku, qty)'
                           'VALUES ("order1", "sku1", 12)')
    [[olid]] = sqlite_session.execute(
        'SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku',
        dict(orderid='order1', sku='sku1'))
    sqlite_session.execute(
        'INSERT INTO batches (reference, sku, _purchased_quantity, eta)'
        'VALUES ("batch1", "sku1", 100, null)')
    [[bid]] = sqlite_session.execute(
        'SELECT id FROM batches WHERE reference=:ref AND sku=:sku',
        dict(ref='batch1', sku='sku1'))
    sqlite_session.execute(
        'INSERT INTO allocations (orderline_id, batch_id) VALUES (:olid, :bid)',
        dict(olid=olid, bid=bid))
    batch = sqlite_session.query(model.Batch).one()

    assert batch._allocations == {model.OrderLine("order1", "sku1", 12)}
Esempio n. 4
0
def test_uow_can_retrieve_batch_and_allocate_it(sqlite_session_factory):
    session = sqlite_session_factory()
    sku_dummy = "ROSEIRA P15"
    batchref_dummy = "b1"
    insert_batch(
        session=session, ref=batchref_dummy, sku=sku_dummy, qty=120,
    )
    session.commit()

    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    # we are testing Unit of Work, not Services Layer
    with uow:
        product = uow.products.get(sku=sku_dummy)
        line = model.OrderLine(order_id="o1", sku=sku_dummy, qty=80)
        product.allocate(line)
        uow.commit()

    batchref = get_allocated_batch_ref(
        session=session, order_id="o1", sku=sku_dummy
    )
    assert batchref == batchref_dummy

def test_uow_can_retrieve_a_batch_and_allocate_to_it(sqlite_session_factory):
    session = sqlite_session_factory()
<<<<<<< HEAD
    insert_batch(session, 'batch1', 'HIPSTER-WORKBENCH', 100, None)
=======
    insert_batch(session, "batch1", "HIPSTER-WORKBENCH", 100, None)
>>>>>>> upstream/master
    session.commit()

    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    with uow:
<<<<<<< HEAD
        product = uow.products.get(sku='HIPSTER-WORKBENCH')
        line = model.OrderLine('o1', 'HIPSTER-WORKBENCH', 10)
        product.allocate(line)
        uow.commit()

    batchref = get_allocated_batch_ref(session, 'o1', 'HIPSTER-WORKBENCH')
    assert batchref == 'batch1'
=======
        product = uow.products.get(sku="HIPSTER-WORKBENCH")
        line = model.OrderLine("o1", "HIPSTER-WORKBENCH", 10)
        product.allocate(line)
        uow.commit()

    batchref = get_allocated_batch_ref(session, "o1", "HIPSTER-WORKBENCH")
    assert batchref == "batch1"
>>>>>>> upstream/master