History is kept by flow id: runs, cascades, rollups and events file the id in their flow column and nodes as <flow id>.<node>, the API answers flow plus flow_name and shows and takes nodes as <key>.<node>; events carry flow_id from the moment they are published; run queue items, the stage cache and cached curves keep ids and keys apart; endpoints, the brain graph, device bindings and search name the id to open
This commit is contained in:
@@ -16,6 +16,7 @@ from fastapi.testclient import TestClient
|
||||
from sqlmodel import Session, delete, select
|
||||
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.flow.dashboards import DashboardDef, WidgetDef
|
||||
from fluksio.flow.store import ISSUED_ID
|
||||
from fluksio.flow.tombstones import names_of
|
||||
from fluksio.models import FlowTombstone, Run
|
||||
@@ -235,6 +236,65 @@ def test_a_results_dashboard_is_made_from_a_flow_id_under_the_flows_key(
|
||||
client.delete(f"{DASHBOARDS}/{board['id']}", headers=superuser_token_headers)
|
||||
|
||||
|
||||
def test_what_opens_a_flow_or_dashboard_names_it_by_id(
|
||||
make: Make, client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
"""A node goes by ``<key>.<node>``, which is what the canvas matches. Where
|
||||
a response leads somewhere, it says the id to go by beside it."""
|
||||
headers = superuser_token_headers
|
||||
key, reader_key = a_key(), a_key()
|
||||
flow_id = make(key)["definition"]["id"]
|
||||
for node, code in (("sensor", SENSOR), ("double", DOUBLE)):
|
||||
client.put(
|
||||
f"{FLOWS}/{flow_id}/nodes/{node}/source",
|
||||
headers=headers,
|
||||
json={"code": code},
|
||||
)
|
||||
client.post(
|
||||
f"{FLOWS}/{flow_id}/publish",
|
||||
headers=headers,
|
||||
json={
|
||||
"version": client.get(f"{FLOWS}/{flow_id}", headers=headers).json()[
|
||||
"definition"
|
||||
]["version"]
|
||||
},
|
||||
)
|
||||
listen = {
|
||||
"id": "listen",
|
||||
"type": "python",
|
||||
"requires": [{"name": f"{key}.reading", "dtype": "float"}],
|
||||
}
|
||||
reader_id = make(reader_key, nodes=[listen])["definition"]["id"]
|
||||
board = client.app.state.dashboard_store.write( # type: ignore[attr-defined]
|
||||
DashboardDef(
|
||||
id=f"d_{reader_key}",
|
||||
name=reader_key,
|
||||
widgets=[
|
||||
WidgetDef(
|
||||
id="shown",
|
||||
type="stat",
|
||||
config={"message": f"{key}.reading", "dtype": "float"},
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
try:
|
||||
far = client.get(f"{FLOWS}/{reader_id}", headers=headers).json()["endpoints"]
|
||||
assert [(e["id"], e["owner_id"]) for e in far] == [
|
||||
(f"flow:{key}.sensor", flow_id)
|
||||
]
|
||||
near = client.get(f"{FLOWS}/{flow_id}", headers=headers).json()["endpoints"]
|
||||
assert (f"dashboard:{board.id}:shown", board.id) in [
|
||||
(e["id"], e["owner_id"]) for e in near
|
||||
]
|
||||
|
||||
graph = client.get(f"{FLOWS}/graph", headers=headers).json()
|
||||
(sensor,) = [n for n in graph["nodes"] if f"{key}.sensor" in n["members"]]
|
||||
assert (sensor["flows"], sensor["flow_ids"]) == ([key], [flow_id])
|
||||
finally:
|
||||
client.delete(f"{DASHBOARDS}/{board.id}", headers=headers)
|
||||
|
||||
|
||||
def test_who_may_create_what(
|
||||
client: TestClient,
|
||||
superuser_token_headers: dict[str, str],
|
||||
@@ -286,7 +346,7 @@ def test_a_deleted_flow_keeps_its_name_and_frees_its_key(
|
||||
) -> None:
|
||||
key = a_key()
|
||||
old = make(key)["definition"]["id"]
|
||||
db.add(Run(id=f"run-{key}", flow=old, status="ok", created_at=datetime.now(UTC)))
|
||||
db.add(Run(id=f"run-{key}", flow_id=old, status="ok", created_at=datetime.now(UTC)))
|
||||
db.commit()
|
||||
controller = client.app.state.flow_controller # type: ignore[attr-defined]
|
||||
controller.state.set(f"{key}.doubled", 1.0)
|
||||
@@ -311,7 +371,7 @@ def test_a_deleted_flow_keeps_its_name_and_frees_its_key(
|
||||
assert made.status_code == 201, made.text
|
||||
new = made.json()["definition"]["id"]
|
||||
assert new != old
|
||||
assert db.exec(select(Run).where(Run.flow == new)).first() is None
|
||||
assert db.exec(select(Run).where(Run.flow_id == new)).first() is None
|
||||
client.delete(f"{FLOWS}/{new}", headers=superuser_token_headers)
|
||||
db.exec(delete(Run).where(Run.id == f"run-{key}")) # type: ignore[call-overload]
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user