This commit is contained in:
@@ -18,14 +18,14 @@ from dibbler.models import (
|
|||||||
from dibbler.queries.product_stock import _product_stock_query
|
from dibbler.queries.product_stock import _product_stock_query
|
||||||
|
|
||||||
|
|
||||||
def _users_owning_product_query(
|
def _product_owners_query(
|
||||||
product_id: int,
|
product_id: int,
|
||||||
use_cache: bool = True,
|
use_cache: bool = True,
|
||||||
until: datetime | None = None,
|
until: datetime | None = None,
|
||||||
cte_name: str = "rec_cte",
|
cte_name: str = "rec_cte",
|
||||||
) -> CTE:
|
) -> CTE:
|
||||||
"""
|
"""
|
||||||
The inner query for calculating the users owning a given product.
|
The inner query for inferring the owners of a given product.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if use_cache:
|
if use_cache:
|
||||||
@@ -134,7 +134,7 @@ def _users_owning_product_query(
|
|||||||
return recursive_cte.union_all(recursive_elements)
|
return recursive_cte.union_all(recursive_elements)
|
||||||
|
|
||||||
|
|
||||||
def users_owning_product(
|
def product_owners(
|
||||||
sql_session: Session,
|
sql_session: Session,
|
||||||
product: Product,
|
product: Product,
|
||||||
use_cache: bool = True,
|
use_cache: bool = True,
|
||||||
@@ -146,12 +146,11 @@ def users_owning_product(
|
|||||||
If 'until' is given, only transactions up to that time are considered.
|
If 'until' is given, only transactions up to that time are considered.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
recursive_cte = _users_owning_product_query(
|
recursive_cte = _product_owners_query(
|
||||||
product_id=product.id,
|
product_id=product.id,
|
||||||
use_cache=use_cache,
|
use_cache=use_cache,
|
||||||
until=until,
|
until=until,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = sql_session.scalars(
|
result = sql_session.scalars(
|
||||||
select(
|
select(
|
||||||
recursive_cte.c.user_id,
|
recursive_cte.c.user_id,
|
||||||
12
tests/queries/test_product_owners.py
Normal file
12
tests/queries/test_product_owners.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
def test_product_owners_no_transactions(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_add_products(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_add_and_buy_products(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_add_and_throw_products(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_multiple_users(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_adjust_stock_down(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_adjust_stock_up(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_negative_stock(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_add_products_from_negative_stock(sql_session: Session) -> None: ...
|
||||||
|
def test_product_owners_interleaved_users(sql_session: Session) -> None: ...
|
||||||
Reference in New Issue
Block a user