CadHubManage/tests/test_plugin_callback_api.py
sladro b19ef1467a feat: Implement CAD batch processing framework with plugin callback handling
- Added configuration for file storage and software plugins in `software_config.yaml`.
- Created core components for batch processing including `CadBatchManager`, `CadTaskRouter`, and `SerialBatchExecutor`.
- Implemented plugin callback handling with `PluginCallbackRegistry` and HTTP client for task submission.
- Developed API endpoint for receiving plugin callbacks in `plugin_callbacks.py`.
- Enhanced data models for batch processing including `BatchJob`, `BatchItem`, and callback payloads.
- Introduced WebSocket support for real-time updates on batch processing status.
- Added comprehensive tests for routing, callback API, and serial executor behavior.
- Documented the implementation plan and core execution rules in `cad-batch-plan.md`.
2026-03-01 08:48:10 +08:00

54 lines
1.5 KiB
Python

from datetime import datetime
from fastapi import FastAPI
from fastapi.testclient import TestClient
from app.api.v1.plugin_callbacks import router
def _build_client() -> TestClient:
app = FastAPI()
app.include_router(router, prefix="/api/v1")
return TestClient(app)
def test_plugin_callback_rejects_invalid_token():
client = _build_client()
response = client.post(
"/api/v1/plugin-callbacks/task-result",
json={
"execution_id": "exec-invalid-token",
"software_id": "creo",
"status": "success",
"result": {"ok": True},
"finished_at": datetime.now().isoformat(),
"token": "wrong-token",
},
)
assert response.status_code == 403
assert response.json()["detail"] == "Invalid callback token"
def test_plugin_callback_accepts_valid_token_and_dedupes():
client = _build_client()
payload = {
"execution_id": "exec-valid-token",
"software_id": "creo",
"status": "success",
"result": {"ok": True},
"finished_at": datetime.now().isoformat(),
"token": "creo-callback-token",
}
first = client.post("/api/v1/plugin-callbacks/task-result", json=payload)
second = client.post("/api/v1/plugin-callbacks/task-result", json=payload)
assert first.status_code == 200
assert first.json()["accepted"] is True
assert second.status_code == 200
assert second.json()["accepted"] is False