oliver-metadata-tool/tests/test_templates.py
SamoilenkoVadym 3deaa5ef40 Initial commit: Oliver Metadata Tool (FastAPI)
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>
2026-02-09 21:23:42 +00:00

93 lines
3.4 KiB
Python

"""Tests for template management endpoints."""
import json
class TestTemplates:
def test_list_templates(self, auth_client):
"""GET /templates/list returns template list."""
response = auth_client.get("/templates/list")
data = response.json()
assert data.get("success") is True
assert "templates" in data
def test_save_template(self, auth_client):
"""POST /templates/save creates a new template."""
response = auth_client.post(
"/templates/save",
content=json.dumps({
"name": "Test Template",
"title": "{filename} - Test",
"subject": "Test subject for {filename}",
"keywords": "test, {year}",
"description": "A test template",
}),
headers={"Content-Type": "application/json"},
)
data = response.json()
assert data.get("success") is True
def test_load_template(self, auth_client):
"""GET /templates/load/{name} loads a template."""
# First save, then load
auth_client.post(
"/templates/save",
content=json.dumps({
"name": "LoadTest",
"title": "{filename}",
"subject": "Subject",
"keywords": "kw",
}),
headers={"Content-Type": "application/json"},
)
response = auth_client.get("/templates/load/LoadTest")
data = response.json()
assert data.get("success") is True
assert data["template"]["name"] == "LoadTest"
def test_load_nonexistent_template(self, auth_client):
"""GET /templates/load/{name} returns 404 for missing template."""
response = auth_client.get("/templates/load/NonExistent12345")
assert response.status_code == 404
def test_save_template_empty_name(self, auth_client):
"""POST /templates/save with empty name returns error."""
response = auth_client.post(
"/templates/save",
content=json.dumps({"name": "", "title": "t", "subject": "s", "keywords": "k"}),
headers={"Content-Type": "application/json"},
)
assert response.status_code == 400
def test_delete_template(self, auth_client):
"""DELETE /templates/delete/{name} removes a template."""
# Create first
auth_client.post(
"/templates/save",
content=json.dumps({
"name": "DeleteMe",
"title": "t",
"subject": "s",
"keywords": "k",
}),
headers={"Content-Type": "application/json"},
)
response = auth_client.delete("/templates/delete/DeleteMe")
data = response.json()
assert data.get("success") is True
def test_preview_template(self, auth_client):
"""POST /templates/preview returns preview output."""
response = auth_client.post(
"/templates/preview",
content=json.dumps({
"title": "{filename} - Preview",
"subject": "Subject for {filename}",
"keywords": "test, {year}",
"sample_filename": "example.pdf",
}),
headers={"Content-Type": "application/json"},
)
data = response.json()
assert data.get("success") is True
assert "preview" in data