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:
@@ -11,6 +11,7 @@ from fluksio.api.routes import flows as flows_route
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.flow.events import event_bus
|
||||
from fluksio.models import Run, RunArtifact, RunMetric, RunNode
|
||||
from tests.utils.flows import put_flow
|
||||
|
||||
PREFIX = f"{settings.API_V1_STR}/flows"
|
||||
|
||||
@@ -51,10 +52,8 @@ def test_flows_require_authentication(client: TestClient) -> None:
|
||||
def test_save_then_read_flow(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
response = client.put(
|
||||
f"{PREFIX}/demo", headers=superuser_token_headers, json=a_flow()
|
||||
)
|
||||
assert response.status_code == 200
|
||||
response = put_flow(client, superuser_token_headers, a_flow(), "demo")
|
||||
assert response.status_code == 201
|
||||
|
||||
response = client.get(f"{PREFIX}/demo", headers=superuser_token_headers)
|
||||
assert response.status_code == 200
|
||||
@@ -68,58 +67,35 @@ def test_save_then_read_flow(
|
||||
assert datetime.fromisoformat(summary["updated_at"]).tzinfo is not None
|
||||
|
||||
|
||||
def test_name_mismatch_is_rejected(
|
||||
def test_a_save_neither_creates_nor_renames(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
response = client.put(
|
||||
f"{PREFIX}/other", headers=superuser_token_headers, json=a_flow("demo")
|
||||
put_flow(client, superuser_token_headers, a_flow(), "demo")
|
||||
current = client.get(f"{PREFIX}/demo", headers=superuser_token_headers).json()
|
||||
document = current["definition"]
|
||||
|
||||
missing = client.put(
|
||||
f"{PREFIX}/nowhere", headers=superuser_token_headers, json=a_flow("nowhere")
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_a_flow_is_known_by_an_id_no_save_changes(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
"""For now the id of a new flow is its key, and the URL names both."""
|
||||
saved = client.put(
|
||||
f"{PREFIX}/identified",
|
||||
assert missing.status_code == 404
|
||||
renamed = client.put(
|
||||
f"{PREFIX}/demo",
|
||||
headers=superuser_token_headers,
|
||||
json=a_flow("identified"),
|
||||
).json()["definition"]
|
||||
assert saved["id"] == "identified"
|
||||
listed = client.get(f"{PREFIX}/", headers=superuser_token_headers).json()["data"]
|
||||
assert {"id": "identified", "name": "identified"}.items() <= next(
|
||||
f for f in listed if f["name"] == "identified"
|
||||
).items()
|
||||
|
||||
json={**document, "name": "other"},
|
||||
)
|
||||
assert renamed.status_code == 409
|
||||
elsewhere = client.put(
|
||||
f"{PREFIX}/identified",
|
||||
f"{PREFIX}/demo",
|
||||
headers=superuser_token_headers,
|
||||
json={**saved, "id": "elsewhere"},
|
||||
json={**document, "id": "elsewhere"},
|
||||
)
|
||||
assert elsewhere.status_code == 400
|
||||
# A key changes by a rename, and that route is not there yet.
|
||||
renamed = client.post(
|
||||
f"{PREFIX}/identified/rename",
|
||||
headers=superuser_token_headers,
|
||||
json={"new_name": "renamed"},
|
||||
)
|
||||
assert renamed.status_code in (404, 405)
|
||||
# Shaped like an id the server issues, which a new key may not be.
|
||||
issued = client.put(
|
||||
f"{PREFIX}/f_k3q7m2xa",
|
||||
headers=superuser_token_headers,
|
||||
json=a_flow("f_k3q7m2xa"),
|
||||
)
|
||||
assert issued.status_code == 400
|
||||
|
||||
client.delete(f"{PREFIX}/identified", headers=superuser_token_headers)
|
||||
|
||||
|
||||
def test_broken_node_is_reported_and_siblings_stay_active(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
client.put(f"{PREFIX}/demo", headers=superuser_token_headers, json=a_flow())
|
||||
put_flow(client, superuser_token_headers, a_flow(), "demo")
|
||||
client.put(
|
||||
f"{PREFIX}/demo/nodes/sensor/source",
|
||||
headers=superuser_token_headers,
|
||||
@@ -143,7 +119,7 @@ def test_broken_node_is_reported_and_siblings_stay_active(
|
||||
def test_running_a_flow_produces_values(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
client.put(f"{PREFIX}/demo", headers=superuser_token_headers, json=a_flow())
|
||||
put_flow(client, superuser_token_headers, a_flow(), "demo")
|
||||
client.put(
|
||||
f"{PREFIX}/demo/nodes/sensor/source",
|
||||
headers=superuser_token_headers,
|
||||
@@ -165,9 +141,7 @@ def test_running_a_flow_produces_values(
|
||||
def test_editing_does_not_deploy_until_published(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
saved = client.put(
|
||||
f"{PREFIX}/staged", headers=superuser_token_headers, json=a_flow("staged")
|
||||
).json()
|
||||
saved = put_flow(client, superuser_token_headers, a_flow("staged"), "staged").json()
|
||||
assert saved["has_draft"] is True
|
||||
# Nothing is running yet, so the engine knows no nodes of this flow.
|
||||
assert (
|
||||
@@ -197,8 +171,8 @@ def test_editing_does_not_deploy_until_published(
|
||||
def test_a_stale_save_is_refused(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
saved = client.put(
|
||||
f"{PREFIX}/contested", headers=superuser_token_headers, json=a_flow("contested")
|
||||
saved = put_flow(
|
||||
client, superuser_token_headers, a_flow("contested"), "contested"
|
||||
).json()
|
||||
stale = saved["definition"]
|
||||
|
||||
@@ -222,8 +196,8 @@ def test_a_stale_save_is_refused(
|
||||
def test_discarding_a_draft_restores_what_is_running(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
saved = client.put(
|
||||
f"{PREFIX}/reverted", headers=superuser_token_headers, json=a_flow("reverted")
|
||||
saved = put_flow(
|
||||
client, superuser_token_headers, a_flow("reverted"), "reverted"
|
||||
).json()
|
||||
client.post(
|
||||
f"{PREFIX}/reverted/publish",
|
||||
@@ -232,10 +206,11 @@ def test_discarding_a_draft_restores_what_is_running(
|
||||
)
|
||||
published = client.get(f"{PREFIX}/reverted", headers=superuser_token_headers).json()
|
||||
|
||||
client.put(
|
||||
f"{PREFIX}/reverted",
|
||||
headers=superuser_token_headers,
|
||||
json={**published["definition"], "title": "Scratch that"},
|
||||
put_flow(
|
||||
client,
|
||||
superuser_token_headers,
|
||||
{**published["definition"], "title": "Scratch that"},
|
||||
"reverted",
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
@@ -251,9 +226,7 @@ def test_discarding_a_draft_restores_what_is_running(
|
||||
def test_stopping_a_flow_takes_it_off_the_engine(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
saved = client.put(
|
||||
f"{PREFIX}/halted", headers=superuser_token_headers, json=a_flow("halted")
|
||||
).json()
|
||||
saved = put_flow(client, superuser_token_headers, a_flow("halted"), "halted").json()
|
||||
client.post(
|
||||
f"{PREFIX}/halted/publish",
|
||||
headers=superuser_token_headers,
|
||||
@@ -286,9 +259,7 @@ def test_stopping_a_flow_takes_it_off_the_engine(
|
||||
def test_pausing_is_reported_back(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
saved = client.put(
|
||||
f"{PREFIX}/held", headers=superuser_token_headers, json=a_flow("held")
|
||||
).json()
|
||||
saved = put_flow(client, superuser_token_headers, a_flow("held"), "held").json()
|
||||
client.post(
|
||||
f"{PREFIX}/held/publish",
|
||||
headers=superuser_token_headers,
|
||||
@@ -318,7 +289,7 @@ def test_unconnected_input_is_surfaced(
|
||||
) -> None:
|
||||
flow = a_flow()
|
||||
flow["nodes"][0]["provides"] = [] # nothing produces "reading" any more
|
||||
client.put(f"{PREFIX}/demo", headers=superuser_token_headers, json=flow)
|
||||
put_flow(client, superuser_token_headers, flow, "demo")
|
||||
|
||||
issues = client.post(
|
||||
f"{PREFIX}/demo/validate", headers=superuser_token_headers
|
||||
@@ -329,7 +300,7 @@ def test_unconnected_input_is_surfaced(
|
||||
def test_delete_flow(
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
client.put(f"{PREFIX}/demo", headers=superuser_token_headers, json=a_flow())
|
||||
put_flow(client, superuser_token_headers, a_flow(), "demo")
|
||||
# Finished: a flow with a live run refuses to be deleted, which is its own
|
||||
# test below.
|
||||
db.add(Run(id="run-1", flow="demo", status="ok", created_at=datetime.now(UTC)))
|
||||
@@ -362,7 +333,7 @@ def test_delete_flow(
|
||||
def test_delete_flow_is_refused_while_a_run_is_live(
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
client.put(f"{PREFIX}/demo", headers=superuser_token_headers, json=a_flow())
|
||||
put_flow(client, superuser_token_headers, a_flow(), "demo")
|
||||
db.add(
|
||||
Run(id="run-live", flow="demo", status="running", created_at=datetime.now(UTC))
|
||||
)
|
||||
@@ -390,8 +361,8 @@ def test_a_node_that_raises_answers_with_its_error(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
"""A manual run fails the way a scheduled one does, not as a 500."""
|
||||
saved = client.put(
|
||||
f"{PREFIX}/failing", headers=superuser_token_headers, json=a_flow("failing")
|
||||
saved = put_flow(
|
||||
client, superuser_token_headers, a_flow("failing"), "failing"
|
||||
).json()
|
||||
client.put(
|
||||
f"{PREFIX}/failing/nodes/sensor/source",
|
||||
@@ -422,9 +393,7 @@ def test_acknowledging_a_failure_is_announced_on_the_bus(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Another browser holds the same marker; the event is what clears it."""
|
||||
saved = client.put(
|
||||
f"{PREFIX}/acked", headers=superuser_token_headers, json=a_flow("acked")
|
||||
).json()
|
||||
saved = put_flow(client, superuser_token_headers, a_flow("acked"), "acked").json()
|
||||
client.post(
|
||||
f"{PREFIX}/acked/publish",
|
||||
headers=superuser_token_headers,
|
||||
@@ -505,9 +474,7 @@ async def test_the_live_socket_ends_when_its_client_goes(
|
||||
def test_saving_a_header_moves_the_node_ports_in_the_draft(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
saved = client.put(
|
||||
f"{PREFIX}/header", headers=superuser_token_headers, json=a_flow("header")
|
||||
).json()
|
||||
saved = put_flow(client, superuser_token_headers, a_flow("header"), "header").json()
|
||||
|
||||
response = client.put(
|
||||
f"{PREFIX}/header/nodes/logger/source",
|
||||
@@ -539,9 +506,7 @@ def test_saving_a_header_moves_the_node_ports_in_the_draft(
|
||||
def test_a_shared_node_in_use_is_retired_only_with_detach(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
client.put(
|
||||
f"{PREFIX}/shared", headers=superuser_token_headers, json=a_flow("shared")
|
||||
)
|
||||
put_flow(client, superuser_token_headers, a_flow("shared"), "shared")
|
||||
client.put(
|
||||
f"{PREFIX}/shared/nodes/sensor/source",
|
||||
headers=superuser_token_headers,
|
||||
@@ -571,9 +536,7 @@ def test_a_shared_node_only_the_published_flow_uses_is_kept(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
"""An unshare in the draft leaves the running flow on the source."""
|
||||
client.put(
|
||||
f"{PREFIX}/unshared", headers=superuser_token_headers, json=a_flow("unshared")
|
||||
)
|
||||
put_flow(client, superuser_token_headers, a_flow("unshared"), "unshared")
|
||||
shared = client.post(
|
||||
f"{PREFIX}/unshared/nodes/sensor/share",
|
||||
headers=superuser_token_headers,
|
||||
@@ -603,9 +566,7 @@ def test_a_shared_source_write_is_audited(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""It goes live at once, so it is recorded like a publish."""
|
||||
client.put(
|
||||
f"{PREFIX}/audited", headers=superuser_token_headers, json=a_flow("audited")
|
||||
)
|
||||
put_flow(client, superuser_token_headers, a_flow("audited"), "audited")
|
||||
client.post(
|
||||
f"{PREFIX}/audited/nodes/sensor/share",
|
||||
headers=superuser_token_headers,
|
||||
|
||||
Reference in New Issue
Block a user