Polish upload drafts, restore availability and offline API docs

This commit is contained in:
Pigway
2026-10-02 00:11:37 +08:00
parent 6652590b84
commit a4a257553a
9 changed files with 96 additions and 5 deletions
+5
View File
@@ -89,6 +89,11 @@
"type": "boolean",
"title": "Model Verified",
"default": false
},
"can_restore": {
"type": "boolean",
"title": "Can Restore",
"default": false
}
},
"type": "object",
+54
View File
@@ -345,3 +345,57 @@ def test_schema_contract(client):
schemas = client.get("/openapi.json").json()["components"]["schemas"]
expected = json.loads((Path(__file__).parent / "schema-contract.json").read_text())
assert {key: schemas[key] for key in expected} == expected
def test_preview_is_draft_until_saved(client, service):
out = BytesIO()
Image.new("RGB", (50, 50), "red").save(out, "PNG")
preview = client.post(
"/api/v1/preview", files={"file": ("draft.png", out.getvalue(), "image/png")}
).json()
assert preview["name"] == "draft.jpg"
assert not any(
x["asset_id"] == preview["asset_id"]
for x in client.get("/api/v1/assets").json()
)
saved = client.post(
"/api/v1/devices/living-room/upload",
json={"type": "image", "asset_id": preview["asset_id"]},
)
assert saved.status_code == 202
service.process_one()
assert any(
x["asset_id"] == preview["asset_id"]
for x in client.get("/api/v1/assets").json()
)
assert service.registry.get("living-room").client.uploads == 0
def test_restore_availability(client, service):
assert client.get("/api/v1/devices/living-room").json()["can_restore"] is False
client.post(
"/api/v1/display", json={"content": {"type": "template", "template": "quote"}}
)
service.process_one()
assert client.get("/api/v1/devices/living-room").json()["can_restore"] is True
def test_template_configuration_reload(client, service):
assert (
client.put(
"/api/v1/templates/quote/config", json={"data": {"quote": "Saved words"}}
).status_code
== 200
)
assert (
client.get("/api/v1/templates/quote").json()["defaults"]["quote"]
== "Saved words"
)
def test_docs_offline_resources(client):
html = client.get("/docs").text
assert "/ui/swagger-ui-bundle.js" in html
assert "cdn.jsdelivr" not in html
assert client.get("/ui/swagger-ui-bundle.js").status_code == 200
assert client.get("/ui/swagger-ui.css").status_code == 200