Flows and dashboards are created by POST under an issued or superuser-pinned id; PUT only updates; deleted flows leave a tombstone with their key; the controller stores by id and runs by key, hooks live under /hooks/<flow id>; a key with state or queued work behind it is refused until cleared

This commit is contained in:
2026-11-02 17:41:23 +01:00
parent fae85f5ecb
commit 08a6376836
63 changed files with 2832 additions and 936 deletions
+66
View File
@@ -0,0 +1,66 @@
"""Flows and dashboards over HTTP, the way most tests want them there."""
from typing import Any
import httpx
from fastapi.testclient import TestClient
from fluksio.core.config import settings
FLOWS = f"{settings.API_V1_STR}/flows"
DASHBOARDS = f"{settings.API_V1_STR}/dashboards"
def put_flow(
client: TestClient,
headers: dict[str, str],
definition: dict[str, Any],
flow_id: str = "",
) -> httpx.Response:
"""Create the flow under *flow_id*, its key unless given, or save over it.
Creating pins the id, so the test can address the flow by what it knows,
which needs a superuser's *headers*. Saving goes from whatever version is
stored. What a test meant by ``PUT`` before ``PUT`` stopped creating.
"""
flow_id = flow_id or definition["name"]
current = client.get(f"{FLOWS}/{flow_id}", headers=headers)
if current.status_code == 404:
return client.post(
f"{FLOWS}/", headers=headers, json={**definition, "id": flow_id}
)
version = current.json()["definition"]["version"]
return client.put(
f"{FLOWS}/{flow_id}",
headers=headers,
json={**definition, "id": flow_id, "version": version},
)
def put_dashboard(
client: TestClient,
headers: dict[str, str],
document: dict[str, Any],
dashboard_id: str = "",
) -> httpx.Response:
"""Create the dashboard under *dashboard_id*, its key unless given, and
save *document* over it, as `put_flow` does for a flow."""
dashboard_id = dashboard_id or document["name"]
current = client.get(f"{DASHBOARDS}/{dashboard_id}?draft=true", headers=headers)
if current.status_code == 404:
created = client.post(
f"{DASHBOARDS}/",
headers=headers,
json={"id": dashboard_id, "name": document["name"]},
)
assert created.status_code == 201, created.text
current = created
return client.put(
f"{DASHBOARDS}/{dashboard_id}",
headers=headers,
json={
**document,
"id": dashboard_id,
"version": current.json()["version"],
},
)