Skip to content

Commit 41484c2

Browse files
committed
Read TUS scenario steps generically
1 parent 75f0049 commit 41484c2

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

  • examples/api2-devdock-tus-assembly

examples/api2-devdock-tus-assembly/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,25 @@ def response_data(response, operation):
8383
return data
8484

8585

86+
def feature_step(scenario, collection_name, feature_id, kind):
87+
steps = scenario.get(collection_name)
88+
if not isinstance(steps, list):
89+
fail(f"{collection_name} must be a list")
90+
91+
for index, step in enumerate(steps):
92+
if not isinstance(step, dict):
93+
fail(f"{collection_name}[{index}] must be an object")
94+
if step.get("featureId") != feature_id:
95+
continue
96+
if step.get("kind") != kind:
97+
fail(f"{collection_name}[{index}] must have kind {kind!r}")
98+
return step
99+
100+
fail(f"scenario has no {collection_name} step for feature {feature_id!r}")
101+
102+
86103
def create_assembly(client, scenario):
87-
feature = scenario["createTusAssembly"]
104+
feature = feature_step(scenario, "preparations", "createTusAssembly", "feature-call")
88105
input_values = list(feature["input"].values())
89106
if len(input_values) != 1:
90107
fail(f"{feature['featureId']} expected exactly one input value")
@@ -150,7 +167,7 @@ def render_path_template(template_config, context, label):
150167

151168

152169
def wait_for_assembly(client, scenario, create_response):
153-
feature = scenario["waitForAssembly"]
170+
feature = feature_step(scenario, "observations", "waitForAssembly", "feature-poll")
154171
context = {"createResponse": create_response, "scenario": scenario}
155172
wait_input = render_path_template(feature["input"], context, feature["featureId"])
156173
return response_data(client.wait_for_assembly(wait_input), feature["featureId"])

0 commit comments

Comments
 (0)