finishing QDRO section
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import io
|
||||
import uuid
|
||||
from fastapi.testclient import TestClient
|
||||
import pytest
|
||||
|
||||
@@ -393,3 +394,70 @@ def test_templates_categories_listing(client: TestClient):
|
||||
assert by_cat_all.get("K1", 0) >= 2
|
||||
assert by_cat_all.get("K2", 0) >= 1
|
||||
|
||||
|
||||
|
||||
def test_templates_download_current_version(client: TestClient):
|
||||
# Upload a DOCX template
|
||||
payload = {
|
||||
"name": f"Download Letter {uuid.uuid4().hex[:8]}",
|
||||
"category": "GENERAL",
|
||||
"description": "Download test",
|
||||
"semantic_version": "1.0.0",
|
||||
}
|
||||
filename = "letter.docx"
|
||||
content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
data_bytes = _dummy_docx_bytes()
|
||||
files = {
|
||||
"file": (filename, data_bytes, content_type),
|
||||
}
|
||||
resp = client.post("/api/templates/upload", data=payload, files=files)
|
||||
assert resp.status_code == 200, resp.text
|
||||
tpl_id = resp.json()["id"]
|
||||
|
||||
# Download current approved version
|
||||
resp = client.get(f"/api/templates/{tpl_id}/download")
|
||||
assert resp.status_code == 200, resp.text
|
||||
# Verify headers
|
||||
assert resp.headers.get("content-type") == content_type
|
||||
cd = resp.headers.get("content-disposition", "")
|
||||
assert "attachment;" in cd and filename in cd
|
||||
# Body should be non-empty and equal to uploaded bytes
|
||||
assert resp.content == data_bytes
|
||||
|
||||
|
||||
def test_templates_download_specific_version_by_id(client: TestClient):
|
||||
# Upload initial version
|
||||
files_v1 = {"file": ("v1.docx", _docx_with_tokens("V1"), "application/vnd.openxmlformats-officedocument.wordprocessingml.document")}
|
||||
resp = client.post(
|
||||
"/api/templates/upload",
|
||||
data={"name": f"MultiVersion {uuid.uuid4().hex[:8]}", "semantic_version": "1.0.0"},
|
||||
files=files_v1,
|
||||
)
|
||||
assert resp.status_code == 200, resp.text
|
||||
tpl_id = resp.json()["id"]
|
||||
|
||||
# Add a second version (do not approve so current stays V1)
|
||||
v2_bytes = _docx_with_tokens("V2 unique")
|
||||
files_v2 = {"file": ("v2.docx", v2_bytes, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")}
|
||||
resp2 = client.post(
|
||||
f"/api/templates/{tpl_id}/versions",
|
||||
data={"semantic_version": "1.1.0", "approve": False},
|
||||
files=files_v2,
|
||||
)
|
||||
assert resp2.status_code == 200, resp2.text
|
||||
|
||||
# Find versions to get v2 id
|
||||
resp_list = client.get(f"/api/templates/{tpl_id}/versions")
|
||||
assert resp_list.status_code == 200
|
||||
versions = resp_list.json()
|
||||
# v2 should be in list; grab the one with semantic_version 1.1.0
|
||||
v2 = next(v for v in versions if v["semantic_version"] == "1.1.0")
|
||||
v2_id = v2["id"]
|
||||
|
||||
# Download specifically v2
|
||||
resp_dl = client.get(f"/api/templates/{tpl_id}/download", params={"version_id": v2_id})
|
||||
assert resp_dl.status_code == 200, resp_dl.text
|
||||
assert resp_dl.headers.get("content-type") == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
cd2 = resp_dl.headers.get("content-disposition", "")
|
||||
assert "v2.docx" in cd2
|
||||
assert resp_dl.content == v2_bytes
|
||||
|
||||
Reference in New Issue
Block a user