31 lines
994 B
Python
31 lines
994 B
Python
from fastapi.testclient import TestClient
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.attachment import AttachmentCategory
|
|
|
|
|
|
def _seed_categories(db: Session) -> list[int]:
|
|
cats = [
|
|
AttachmentCategory(name="TEST_CERT", sort_order=1, is_active=True),
|
|
AttachmentCategory(name="TEST_EXTRA", sort_order=2, is_active=True),
|
|
AttachmentCategory(name="TEST_OFF", sort_order=3, is_active=False),
|
|
]
|
|
for c in cats:
|
|
db.add(c)
|
|
db.commit()
|
|
for c in cats:
|
|
db.refresh(c)
|
|
return [c.id for c in cats]
|
|
|
|
|
|
def test_categories_lists_active_only(client: TestClient, db: Session):
|
|
_seed_categories(db)
|
|
resp = client.get("/CargoTrace/attachment/categories")
|
|
assert resp.status_code == 200
|
|
names = [c["name"] for c in resp.json()]
|
|
assert "TEST_CERT" in names
|
|
assert "TEST_EXTRA" in names
|
|
assert "TEST_OFF" not in names
|
|
# sorted by sort_order then name
|
|
assert names.index("TEST_CERT") < names.index("TEST_EXTRA")
|