Complete Flask → FastAPI migration with: - FastAPI app with session auth, Azure AD SSO, rate limiting - SQLite-backed session store (survives restarts) - Bulk AI metadata generation with SSE progress - Admin panel (user management, audit log, AI usage) - Subpath deployment support (ROOT_PATH config) - Docker + deploy.sh for production deployment - Test suite (auth, upload, templates, imports, admin, sessions) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
"""Tests for upload endpoints."""
|
|
|
|
import io
|
|
from pathlib import Path
|
|
|
|
|
|
class TestUpload:
|
|
def test_upload_no_files(self, auth_client):
|
|
"""POST /upload with no files returns error."""
|
|
response = auth_client.post(
|
|
"/upload",
|
|
data={"metadata_source": "manual"},
|
|
files={"files": ("", b"", "application/octet-stream")},
|
|
)
|
|
assert response.status_code == 400
|
|
|
|
def test_upload_manual_source(self, auth_client, sample_pdf):
|
|
"""POST /upload with manual source processes file."""
|
|
with open(sample_pdf, "rb") as f:
|
|
response = auth_client.post(
|
|
"/upload",
|
|
data={"metadata_source": "manual"},
|
|
files={"files": ("test.pdf", f, "application/pdf")},
|
|
)
|
|
data = response.json()
|
|
assert data.get("success") is True
|
|
assert "session_id" in data
|
|
assert len(data["files"]) == 1
|
|
|
|
def test_upload_response_no_filepath(self, auth_client, sample_pdf):
|
|
"""API response should not expose server file paths."""
|
|
with open(sample_pdf, "rb") as f:
|
|
response = auth_client.post(
|
|
"/upload",
|
|
data={"metadata_source": "manual"},
|
|
files={"files": ("test.pdf", f, "application/pdf")},
|
|
)
|
|
data = response.json()
|
|
for file_result in data.get("files", []):
|
|
assert "filepath" not in file_result
|
|
|
|
|
|
class TestUploadExcel:
|
|
def test_upload_excel_requires_auth(self, client):
|
|
"""POST /upload-excel requires authentication."""
|
|
client.cookies.clear()
|
|
response = client.post(
|
|
"/upload-excel",
|
|
files={"excel_file": ("test.xlsx", b"fake", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")},
|
|
follow_redirects=False,
|
|
)
|
|
assert response.status_code == 302
|