feat(server): add attachment schemas and GET /attachment/categories

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-08-12 13:37:24 +08:00
parent baa841ae42
commit ab774b8661
4 changed files with 223 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
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")