Clients take a flow's id or key: one resolver in the SDK, id first, explicit id:/key:, a warning for reads and a refusal for changes when a name means two flows, deleted flows found by their last key; sync creates by POST, retries a create race through the drift checks and reports the id; MCP gets create_flow and resolves every flow argument with the caller's token; displays show flow_name; an engine from before ids is named as such
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
"""Which flow an argument names: the one matrix every client relies on."""
|
||||
|
||||
import pytest
|
||||
|
||||
from fluksio.sdk.resolve import Resolved, Unresolved, resolve
|
||||
|
||||
#: `heating` is the grandfathered id of the flow now keyed `warmth`; a later
|
||||
#: flow took the key `heating` under an issued id.
|
||||
FLOWS = [
|
||||
("heating", "warmth"),
|
||||
("f_k3q7m2xa", "heating"),
|
||||
("train", "train"),
|
||||
("f_aaaaaaaa", "lights"),
|
||||
]
|
||||
|
||||
|
||||
def test_an_id_alone_picks_its_flow():
|
||||
assert resolve("f_aaaaaaaa", FLOWS) == Resolved("f_aaaaaaaa", "lights")
|
||||
|
||||
|
||||
def test_a_key_alone_picks_its_flow():
|
||||
assert resolve("lights", FLOWS) == Resolved("f_aaaaaaaa", "lights")
|
||||
|
||||
|
||||
def test_an_id_that_is_its_own_key_is_no_ambiguity():
|
||||
assert resolve("train", FLOWS, mutation=True) == Resolved("train", "train")
|
||||
|
||||
|
||||
def test_one_flows_id_and_anothers_key_reads_the_id_with_a_warning():
|
||||
found = resolve("heating", FLOWS)
|
||||
|
||||
assert (found.id, found.key) == ("heating", "warmth")
|
||||
assert found.warning == (
|
||||
"'heating' is the id of 'warmth' and the key of 'f_k3q7m2xa'. "
|
||||
"Using the id. Pass key:heating for the other."
|
||||
)
|
||||
|
||||
|
||||
def test_a_change_refuses_a_name_two_flows_answer_to():
|
||||
with pytest.raises(Unresolved, match="Pass id:heating or key:heating"):
|
||||
resolve("heating", FLOWS, mutation=True)
|
||||
|
||||
|
||||
def test_the_explicit_forms_say_which():
|
||||
assert resolve("id:heating", FLOWS, mutation=True) == Resolved("heating", "warmth")
|
||||
assert resolve("key:heating", FLOWS, mutation=True) == Resolved(
|
||||
"f_k3q7m2xa", "heating"
|
||||
)
|
||||
|
||||
|
||||
def test_neither_names_the_closest_keys():
|
||||
with pytest.raises(Unresolved) as caught:
|
||||
resolve("lihgts", FLOWS)
|
||||
|
||||
assert str(caught.value) == (
|
||||
"No flow with the id or key 'lihgts'. Closest keys: lights."
|
||||
)
|
||||
with pytest.raises(Unresolved, match="No flow with the key 'f_aaaaaaaa'"):
|
||||
resolve("key:f_aaaaaaaa", FLOWS)
|
||||
|
||||
|
||||
def test_an_explicit_id_outlives_its_flow():
|
||||
"""History stays filed under a deleted flow's id, which nobody lists."""
|
||||
assert resolve("id:f_gone0000", FLOWS) == Resolved("f_gone0000", "")
|
||||
|
||||
|
||||
def test_a_key_history_holds_twice_is_refused_not_guessed():
|
||||
"""A deleted flow and the later one that took its key."""
|
||||
history = [("f_old00000", "train"), ("f_new00000", "train")]
|
||||
|
||||
for value in ("train", "key:train"):
|
||||
with pytest.raises(Unresolved, match="f_old00000, f_new00000"):
|
||||
resolve(value, history)
|
||||
assert resolve("id:f_old00000", history) == Resolved("f_old00000", "train")
|
||||
Reference in New Issue
Block a user