add tests forn forms, products, productors
All checks were successful
Deploy Amap / deploy (push) Successful in 3m45s
All checks were successful
Deploy Amap / deploy (push) Successful in 3m45s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from sqlmodel import Session, select
|
||||
import src.models as models
|
||||
import src.productors.exceptions as exceptions
|
||||
|
||||
def get_all(
|
||||
session: Session,
|
||||
@@ -20,7 +21,9 @@ def get_one(session: Session, productor_id: int) -> models.ProductorPublic:
|
||||
return session.get(models.Productor, productor_id)
|
||||
|
||||
def create_one(session: Session, productor: models.ProductorCreate) -> models.ProductorPublic:
|
||||
productor_create = productor.model_dump(exclude_unset=True, exclude="payment_methods")
|
||||
if not productor:
|
||||
raise exceptions.ProductorCreateError('ProductorCreate input cannot be None')
|
||||
productor_create = productor.model_dump(exclude_unset=True, exclude='payment_methods')
|
||||
new_productor = models.Productor(**productor_create)
|
||||
|
||||
new_productor.payment_methods = [
|
||||
@@ -40,21 +43,21 @@ def update_one(session: Session, id: int, productor: models.ProductorUpdate) ->
|
||||
result = session.exec(statement)
|
||||
new_productor = result.first()
|
||||
if not new_productor:
|
||||
return None
|
||||
raise exceptions.ProductorNotFoundError(f'Productor {id} not found')
|
||||
|
||||
productor_updates = productor.model_dump(exclude_unset=True)
|
||||
if "payment_methods" in productor_updates:
|
||||
if 'payment_methods' in productor_updates:
|
||||
new_productor.payment_methods.clear()
|
||||
for pm in productor_updates["payment_methods"]:
|
||||
for pm in productor_updates['payment_methods']:
|
||||
new_productor.payment_methods.append(
|
||||
models.PaymentMethod(
|
||||
name=pm["name"],
|
||||
details=pm["details"],
|
||||
name=pm['name'],
|
||||
details=pm['details'],
|
||||
productor_id=id,
|
||||
max=pm["max"]
|
||||
max=pm['max']
|
||||
)
|
||||
)
|
||||
del productor_updates["payment_methods"]
|
||||
del productor_updates['payment_methods']
|
||||
|
||||
for key, value in productor_updates.items():
|
||||
setattr(new_productor, key, value)
|
||||
@@ -68,7 +71,7 @@ def delete_one(session: Session, id: int) -> models.ProductorPublic:
|
||||
result = session.exec(statement)
|
||||
productor = result.first()
|
||||
if not productor:
|
||||
return None
|
||||
raise exceptions.ProductorNotFoundError(f'Productor {id} not found')
|
||||
result = models.ProductorPublic.model_validate(productor)
|
||||
session.delete(productor)
|
||||
session.commit()
|
||||
|
||||
Reference in New Issue
Block a user