fix all pylint warnings, add tests (wip) fix recap

This commit is contained in:
2026-03-06 00:00:01 +01:00
parent 60812652cf
commit b4b4fa7643
25 changed files with 845 additions and 376 deletions

View File

@@ -1,7 +1,6 @@
import src.messages as messages
import src.products.exceptions as exceptions
from sqlmodel import Session, select
from src import models
from src import messages, models
from src.products import exceptions
def get_all(
@@ -27,13 +26,17 @@ def get_all(
return session.exec(statement.order_by(models.Product.name)).all()
def get_one(session: Session, product_id: int) -> models.ProductPublic:
def get_one(
session: Session,
product_id: int,
) -> models.ProductPublic:
return session.get(models.Product, product_id)
def create_one(
session: Session,
product: models.ProductCreate) -> models.ProductPublic:
session: Session,
product: models.ProductCreate,
) -> models.ProductPublic:
if not product:
raise exceptions.ProductCreateError(
messages.Messages.invalid_input(
@@ -50,10 +53,11 @@ def create_one(
def update_one(
session: Session,
id: int,
product: models.ProductUpdate) -> models.ProductPublic:
statement = select(models.Product).where(models.Product.id == id)
session: Session,
_id: int,
product: models.ProductUpdate
) -> models.ProductPublic:
statement = select(models.Product).where(models.Product.id == _id)
result = session.exec(statement)
new_product = result.first()
if not new_product:
@@ -74,8 +78,11 @@ def update_one(
return new_product
def delete_one(session: Session, id: int) -> models.ProductPublic:
statement = select(models.Product).where(models.Product.id == id)
def delete_one(
session: Session,
_id: int
) -> models.ProductPublic:
statement = select(models.Product).where(models.Product.id == _id)
result = session.exec(statement)
product = result.first()
if not product:
@@ -87,11 +94,13 @@ def delete_one(session: Session, id: int) -> models.ProductPublic:
return result
def is_allowed(
session: Session,
user: models.User,
_id: int,
product: models.ProductCreate
session: Session,
user: models.User,
_id: int = None,
product: models.ProductCreate = None,
) -> bool:
if not _id and not product:
return False
if not _id:
statement = (
select(models.Product)
@@ -113,4 +122,4 @@ def is_allowed(
.where(models.Productor.type.in_([r.name for r in user.roles]))
.distinct()
)
return len(session.exec(statement).all()) > 0
return len(session.exec(statement).all()) > 0