Add tests/test_categories.py

This commit is contained in:
2026-04-11 03:58:51 +00:00
parent 35ca16e3b5
commit 55e00bb01f

33
tests/test_categories.py Normal file
View File

@@ -0,0 +1,33 @@
from app.services import category_service
from app.schemas.category import CategoryCreate
def test_create_and_get_category(db):
cat = category_service.create_category(db, CategoryCreate(name="Electrónica", description="Productos electrónicos"))
assert cat.id is not None
assert cat.name == "Electrónica"
found = category_service.get_category(db, cat.id)
assert found is not None
assert found.name == "Electrónica"
def test_list_categories(db):
category_service.create_category(db, CategoryCreate(name="Cat1"))
category_service.create_category(db, CategoryCreate(name="Cat2"))
cats = category_service.get_categories(db)
assert len(cats) == 2
def test_update_category(db):
cat = category_service.create_category(db, CategoryCreate(name="Original"))
from app.schemas.category import CategoryUpdate
updated = category_service.update_category(db, cat.id, CategoryUpdate(name="Modificado"))
assert updated.name == "Modificado"
def test_delete_category(db):
cat = category_service.create_category(db, CategoryCreate(name="ToDelete"))
ok = category_service.delete_category(db, cat.id)
assert ok is True
assert category_service.get_category(db, cat.id) is None