fixup! WIP
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from sqlalchemy import and_, literal, or_, select
|
from sqlalchemy import and_, literal, not_, or_, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from dibbler.models import Product
|
from dibbler.models import Product
|
||||||
@@ -7,7 +7,7 @@ from dibbler.models import Product
|
|||||||
def search_product(
|
def search_product(
|
||||||
string: str,
|
string: str,
|
||||||
sql_session: Session,
|
sql_session: Session,
|
||||||
find_hidden_products=True,
|
find_hidden_products=False,
|
||||||
) -> Product | list[Product]:
|
) -> Product | list[Product]:
|
||||||
exact_match = sql_session.scalars(
|
exact_match = sql_session.scalars(
|
||||||
select(Product).where(
|
select(Product).where(
|
||||||
@@ -15,7 +15,7 @@ def search_product(
|
|||||||
Product.bar_code == string,
|
Product.bar_code == string,
|
||||||
and_(
|
and_(
|
||||||
Product.name == string,
|
Product.name == string,
|
||||||
literal(True) if find_hidden_products else not Product.hidden,
|
literal(True) if find_hidden_products else not_(Product.hidden),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -30,7 +30,7 @@ def search_product(
|
|||||||
Product.bar_code.ilike(f"%{string}%"),
|
Product.bar_code.ilike(f"%{string}%"),
|
||||||
and_(
|
and_(
|
||||||
Product.name.ilike(f"%{string}%"),
|
Product.name.ilike(f"%{string}%"),
|
||||||
literal(True) if find_hidden_products else not Product.hidden,
|
literal(True) if find_hidden_products else not_(Product.hidden),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ def test_search_product_name_exact_match(sql_session: Session) -> None:
|
|||||||
def test_search_product_name_partial_match(sql_session: Session) -> None:
|
def test_search_product_name_partial_match(sql_session: Session) -> None:
|
||||||
insert_test_data(sql_session)
|
insert_test_data(sql_session)
|
||||||
|
|
||||||
result = search_product("Product", sql_session)
|
result = search_product("Test Product", sql_session)
|
||||||
assert isinstance(result, list)
|
assert isinstance(result, list)
|
||||||
assert len(result) == 2
|
assert len(result) == 2
|
||||||
names = {product.name for product in result}
|
names = {product.name for product in result}
|
||||||
|
|||||||
Reference in New Issue
Block a user