feat: 完成工作流调度与上传下载 API
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
WORKSPACE = Path(__file__).resolve().parent.parent.parent
|
||||
ECHO_MANIFEST = json.loads(
|
||||
(WORKSPACE / "wov-node-echo" / "node.manifest.json").read_text(encoding="utf-8")
|
||||
)
|
||||
|
||||
|
||||
def test_health() -> None:
|
||||
with TestClient(app) as client:
|
||||
root = client.get("/", follow_redirects=False)
|
||||
assert root.status_code == 200
|
||||
assert "WOV 应用中心" in root.text
|
||||
|
||||
docs = client.get("/docs")
|
||||
assert docs.status_code == 200
|
||||
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["service"] == "wov-api"
|
||||
|
||||
|
||||
def test_register_validation_errors() -> None:
|
||||
with TestClient(app) as client:
|
||||
assert client.post("/api/admin/nodes", json={}).status_code == 422
|
||||
invalid = dict(ECHO_MANIFEST, id="")
|
||||
assert client.post("/api/admin/nodes", json=invalid).status_code == 422
|
||||
invalid = dict(ECHO_MANIFEST, repo_dir="")
|
||||
assert client.post("/api/admin/nodes", json=invalid).status_code == 422
|
||||
invalid = dict(ECHO_MANIFEST, max_concurrency=0)
|
||||
assert client.post("/api/admin/nodes", json=invalid).status_code == 422
|
||||
|
||||
|
||||
def test_node_lifecycle_and_invoke() -> None:
|
||||
with TestClient(app) as client:
|
||||
registered = client.post("/api/admin/nodes", json=ECHO_MANIFEST)
|
||||
assert registered.status_code == 200
|
||||
assert registered.json()["id"] == "echo"
|
||||
|
||||
nodes = client.get("/api/admin/nodes")
|
||||
assert nodes.status_code == 200
|
||||
assert [node["id"] for node in nodes.json()] == ["echo"]
|
||||
|
||||
node = client.get("/api/admin/nodes/echo")
|
||||
assert node.status_code == 200
|
||||
assert node.json()["capability"] == "echo"
|
||||
|
||||
assert client.get("/api/admin/nodes/missing").status_code == 404
|
||||
|
||||
invoked = client.post(
|
||||
"/api/admin/nodes/echo/invoke",
|
||||
json={
|
||||
"run_id": "run_api",
|
||||
"inputs": {"text": "api test"},
|
||||
"params": {},
|
||||
},
|
||||
)
|
||||
assert invoked.status_code == 200
|
||||
assert invoked.json()["status"] == "completed"
|
||||
assert invoked.json()["outputs"]["text"] == "api test"
|
||||
|
||||
invoked_default = client.post(
|
||||
"/api/admin/nodes/echo/invoke",
|
||||
json={"inputs": {}},
|
||||
)
|
||||
assert invoked_default.status_code == 200
|
||||
assert invoked_default.json()["status"] == "completed"
|
||||
assert invoked_default.json()["outputs"]["text"] == "echo"
|
||||
|
||||
instances = client.get("/api/admin/node-instances")
|
||||
assert instances.status_code == 200
|
||||
assert len(instances.json()) >= 1
|
||||
instance_id = instances.json()[0]["id"]
|
||||
|
||||
node_instances = client.get("/api/admin/nodes/echo/instances")
|
||||
assert node_instances.status_code == 200
|
||||
assert node_instances.json()[0]["id"] == instance_id
|
||||
|
||||
assert client.get("/api/admin/nodes/missing/instances").status_code == 404
|
||||
|
||||
stopped = client.post(f"/api/admin/node-instances/{instance_id}/stop")
|
||||
assert stopped.status_code == 200
|
||||
assert stopped.json()["stopped"] == instance_id
|
||||
|
||||
assert client.post("/api/admin/node-instances/missing/stop").status_code == 404
|
||||
|
||||
deleted = client.delete("/api/admin/nodes/echo")
|
||||
assert deleted.status_code == 200
|
||||
assert deleted.json()["deleted"] == "echo"
|
||||
|
||||
assert client.get("/api/admin/nodes/echo").status_code == 404
|
||||
assert client.delete("/api/admin/nodes/echo").status_code == 404
|
||||
Reference in New Issue
Block a user