refactor: FastAPI best practices — return types, Pydantic schemas, middleware, code dedup
- Все 18 роутов получили return type annotations
- Создан schemas.py с Pydantic-моделями (ScanOut, PackageOut, FindingOut, ...)
- API-роуты: response_model на list/detail/export/stats
- 404 через HTTPException(404) вместо {'detail':'Not found'} (200)
- RequestLoggingMiddleware: method, path, status, duration_ms
- Глобальный exception handler: ловит необработанные исключения → 500
- _parse_flagged(): вынесен дублирующийся string→bool
- parse_package_path(): общий для web.py и api_packages.py
- selectinload: вынесены в top-level imports
- harvester: makedirs/mkdtemp/rmtree обёрнуты в asyncio.to_thread()
This commit is contained in:
@@ -34,8 +34,7 @@ async def test_scan_stats_empty(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_not_found(client):
|
||||
resp = await client.get("/api/v1/scans/99999")
|
||||
assert resp.status_code == 200
|
||||
assert "detail" in resp.json()
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -129,8 +128,7 @@ async def test_package_with_data(client, sample_flagged_scan):
|
||||
@pytest.mark.asyncio
|
||||
async def test_package_not_found(client):
|
||||
resp = await client.get("/api/v1/packages/nonexistent/1.0")
|
||||
assert resp.status_code == 200
|
||||
assert "detail" in resp.json()
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
# --- Findings ---
|
||||
|
||||
Reference in New Issue
Block a user