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
+32 -19
View File
@@ -12,6 +12,7 @@ from fluksio.cloud import config as cloud_config
from fluksio.core.config import settings
from fluksio.flow.devices import DeviceState
from fluksio.main import app
from tests.utils.flows import put_flow
PREFIX = f"{settings.API_V1_STR}/devices"
#: What the openpanel firmware calls, kept as aliases.
@@ -54,8 +55,10 @@ def _dashboard(client: TestClient, headers: dict[str, str], name: str) -> dict:
A new one is a draft, and a panel is only ever shown what is published.
"""
created = client.post(f"{DASHBOARDS}/{name}", headers=headers)
assert created.status_code == 200, created.text
created = client.post(
f"{DASHBOARDS}/", headers=headers, json={"id": name, "name": name}
)
assert created.status_code == 201, created.text
published = client.post(
f"{DASHBOARDS}/{name}/publish",
headers=headers,
@@ -95,7 +98,11 @@ def test_assign_and_read_back(
client: TestClient, superuser_token_headers: dict[str, str]
) -> None:
for name in ("hall_a", "hall_b"):
client.post(f"{DASHBOARDS}/{name}", headers=superuser_token_headers)
client.post(
f"{DASHBOARDS}/",
headers=superuser_token_headers,
json={"id": name, "name": name},
)
_panels(
client,
@@ -132,7 +139,11 @@ def test_touch_belongs_to_the_device(
The same dashboard may hang on a hallway tablet and on a desk browser, so
the flag rides on the panel and each one answers for itself.
"""
client.post(f"{DASHBOARDS}/shared", headers=superuser_token_headers)
client.post(
f"{DASHBOARDS}/",
headers=superuser_token_headers,
json={"id": "shared", "name": "shared"},
)
_panels(
client,
superuser_token_headers,
@@ -553,12 +564,8 @@ def _publish_flow(
) -> dict:
"""Write a flow and publish it, replacing whatever was there."""
client.delete(f"{FLOWS}/{name}", headers=headers)
saved = client.put(
f"{FLOWS}/{name}",
headers=headers,
json={"name": name, "nodes": nodes, "version": 0, **more},
)
assert saved.status_code == 200, saved.text
saved = put_flow(client, headers, {"name": name, "nodes": nodes, **more}, name)
assert saved.is_success, saved.text
published = client.post(
f"{FLOWS}/{name}/publish",
headers=headers,
@@ -590,10 +597,10 @@ def test_a_devices_io_comes_from_its_device_nodes(
_panels(client, superuser_token_headers, {"panels": [{"id": "porch_io"}]})
_publish_flow(client, superuser_token_headers, "porch", [PORCH_NODE])
# A draft wires nothing until it is published.
client.put(
f"{FLOWS}/porch_draft",
headers=superuser_token_headers,
json={
put_flow(
client,
superuser_token_headers,
{
"name": "porch_draft",
"nodes": [
_device_node(
@@ -603,6 +610,7 @@ def test_a_devices_io_comes_from_its_device_nodes(
],
"version": 0,
},
"porch_draft",
)
first = client.get(f"{PREFIX}/porch_io", headers=superuser_token_headers)
@@ -792,10 +800,10 @@ def test_a_port_wired_twice_or_an_unknown_device_is_an_issue(
"ports": [{"port": "touch", "direction": "in", "dtype": "bool"}],
}
store._write_states(states)
client.put(
f"{FLOWS}/porch_too",
headers=superuser_token_headers,
json={
put_flow(
client,
superuser_token_headers,
{
"name": "porch_too",
"version": client.get(
f"{FLOWS}/porch_too", headers=superuser_token_headers
@@ -816,6 +824,7 @@ def test_a_port_wired_twice_or_an_unknown_device_is_an_issue(
)
],
},
"porch_too",
)
assert codes("porch_too") == {
("device_port", "relay", True),
@@ -1440,7 +1449,11 @@ def test_a_panel_credential_cannot_move_artifacts(
the scope check has to be handed the request there too — without it a panel
would act as whoever approved it.
"""
client.post(f"{DASHBOARDS}/panel_art", headers=superuser_token_headers)
client.post(
f"{DASHBOARDS}/",
headers=superuser_token_headers,
json={"id": "panel_art", "name": "panel_art"},
)
_panels(
client,
superuser_token_headers,