Beispiel #1
0
def reallocate(
    event: events.Deallocated,
    uow: SqlAlchemyUnitOfWork,
):
    with uow:
        product = uow[Product].get(event.sku)
        product.messages.append(commands.Allocate(**asdict(event)))
        uow.commit()
Beispiel #2
0
def remove_allocation_from_read_model(
    event: events.Deallocated,
    uow: SqlAlchemyUnitOfWork,
):
    with uow:
        uow.session.execute(
            """
            DELETE FROM allocations_view
            WHERE orderid = :orderid AND sku = :sku
            """,
            dict(orderid=event.orderid, sku=event.sku),
        )
        uow.commit()
Beispiel #3
0
def add_allocation_to_read_model(
    event: events.Allocated,
    uow: SqlAlchemyUnitOfWork,
):
    with uow:
        uow.session.execute(
            """
            INSERT INTO allocations_view (orderid, sku, batchref)
            VALUES (:orderid, :sku, :batchref)
            """,
            dict(orderid=event.orderid, sku=event.sku,
                 batchref=event.batchref),
        )
        uow.commit()
Beispiel #4
0
 def wrapper(sku: str, ref: str):
     nonlocal _batch_ref
     nonlocal _sku
     _batch_ref = ref
     _sku = sku
     delete_product_batch_and_allocation(session, sku, _batch_ref)
     return SqlAlchemyUnitOfWork([Product], lambda: session)
Beispiel #5
0
def test_uow_can_retrieve_a_batch_and_allocate_to_it(
    get_session: SessionMaker,
    session_with_product: Any,
):
    ref, sku = random_batchref(), random_sku()
    session = session_with_product(ref, sku, 100, None)
    uow = SqlAlchemyUnitOfWork([Product], get_session)

    with uow:
        product = uow[Product].get(sku)
        if product:
            line = OrderLine("o1", sku, 10)
            product.allocate(line)
            uow.commit()

    ref_got = get_allocated_batch_ref(session, "o1", sku)
    assert ref == ref_got
Beispiel #6
0
def create_uow(get_session: Optional[SessionMaker] = None):
    return SqlAlchemyUnitOfWork(
        [Product],
        repo_maker={
            Product:
            lambda session: SqlAlchemyProductRepository(Product, session)
        },
        get_session=get_session,
    )
Beispiel #7
0
    def uow(self):
        from fastmsa.uow import SqlAlchemyUnitOfWork
        from tests.app.adapters.repos import SqlAlchemyProductRepository
        from tests.app.domain.aggregates import Product

        repo_maker: RepoMakerDict = {
            Product:
            lambda session: SqlAlchemyProductRepository(Product, session)
        }

        return SqlAlchemyUnitOfWork([Product], repo_maker=repo_maker)
Beispiel #8
0
def read_test_baskets():
    with SqlAlchemyUnitOfWork(Basket) as uow:
        baskets = uow.repo.all()
        print(baskets)
        return baskets
    ...