Skip to content

Commit f5b8c80

Browse files
author
Alan Christie
committed
fix: Runnign workflows now expect variables
1 parent 37882c2 commit f5b8c80

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

tests/api_adapter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
9898
item = {"id": wfid, "workflow": value}
9999
return item
100100

101-
def create_running_workflow(self, *, workflow_id: str, project_id: str) -> str:
101+
def create_running_workflow(
102+
self, *, workflow_id: str, project_id: str, variables: Dict[str, Any]
103+
) -> str:
104+
assert isinstance(variables, dict)
105+
102106
UnitTestAPIAdapter.lock.acquire()
103107
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
104108
running_workflow = Unpickler(pickle_file).load()
@@ -110,6 +114,7 @@ def create_running_workflow(self, *, workflow_id: str, project_id: str) -> str:
110114
"success": False,
111115
"workflow": workflow_id,
112116
"project_id": project_id,
117+
"variables": variables,
113118
}
114119
running_workflow[running_workflow_id] = record
115120

tests/test_test_api_adapter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_create_running_workflow():
7878
response = utaa.create_running_workflow(
7979
workflow_id=response["id"],
8080
project_id=TEST_PROJECT_ID,
81+
variables={"x": 1},
8182
)
8283

8384
# Assert
@@ -90,7 +91,9 @@ def test_get_running_workflow():
9091
response = utaa.create_workflow(workflow_definition={"name": "blah"})
9192
wfid = response["id"]
9293
response = utaa.create_running_workflow(
93-
workflow_id=wfid, project_id=TEST_PROJECT_ID
94+
workflow_id=wfid,
95+
project_id=TEST_PROJECT_ID,
96+
variables={"x": 1},
9497
)
9598
rwfid = response["id"]
9699

@@ -101,6 +104,7 @@ def test_get_running_workflow():
101104
rwf = response["running_workflow"]
102105
assert not rwf["done"]
103106
assert rwf["workflow"] == wfid
107+
assert rwf["variables"] == {"x": 1}
104108

105109

106110
def test_set_running_workflow_done_when_success():
@@ -110,6 +114,7 @@ def test_set_running_workflow_done_when_success():
110114
response = utaa.create_running_workflow(
111115
workflow_id=response["id"],
112116
project_id=TEST_PROJECT_ID,
117+
variables={},
113118
)
114119
rwfid = response["id"]
115120

@@ -129,6 +134,7 @@ def test_set_running_workflow_done_when_failed():
129134
response = utaa.create_running_workflow(
130135
workflow_id=response["id"],
131136
project_id=TEST_PROJECT_ID,
137+
variables={},
132138
)
133139
rwfid = response["id"]
134140

@@ -148,6 +154,7 @@ def test_create_running_workflow_step():
148154
response = utaa.create_running_workflow(
149155
workflow_id=response["id"],
150156
project_id=TEST_PROJECT_ID,
157+
variables={},
151158
)
152159

153160
# Act
@@ -165,7 +172,9 @@ def test_get_running_workflow_step():
165172
response = utaa.create_workflow(workflow_definition={"name": "blah"})
166173
wfid = response["id"]
167174
response = utaa.create_running_workflow(
168-
workflow_id=wfid, project_id=TEST_PROJECT_ID
175+
workflow_id=wfid,
176+
project_id=TEST_PROJECT_ID,
177+
variables={},
169178
)
170179
rwfid = response["id"]
171180
response = utaa.create_running_workflow_step(
@@ -189,7 +198,9 @@ def test_get_running_workflow_steps():
189198
response = utaa.create_workflow(workflow_definition={"name": "blah"})
190199
wfid = response["id"]
191200
response = utaa.create_running_workflow(
192-
workflow_id=wfid, project_id=TEST_PROJECT_ID
201+
workflow_id=wfid,
202+
project_id=TEST_PROJECT_ID,
203+
variables={},
193204
)
194205
rwfid = response["id"]
195206
response = utaa.create_running_workflow_step(

tests/test_test_instance_launcher.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_launch_nop(basic_launcher):
3030
response = utaa.create_running_workflow(
3131
workflow_id=response["id"],
3232
project_id=TEST_PROJECT_ID,
33+
variables={},
3334
)
3435
response = utaa.create_running_workflow_step(
3536
running_workflow_id=response["id"], step="step-1"
@@ -59,6 +60,7 @@ def test_launch_nop_fail(basic_launcher):
5960
response = utaa.create_running_workflow(
6061
workflow_id=response["id"],
6162
project_id=TEST_PROJECT_ID,
63+
variables={},
6264
)
6365
response = utaa.create_running_workflow_step(
6466
running_workflow_id=response["id"], step="step-1"
@@ -88,6 +90,7 @@ def test_launch_smiles_to_file(basic_launcher):
8890
response = utaa.create_running_workflow(
8991
workflow_id=response["id"],
9092
project_id=TEST_PROJECT_ID,
93+
variables={},
9194
)
9295
response = utaa.create_running_workflow_step(
9396
running_workflow_id=response["id"], step="step-1"

tests/test_workflow_engine_examples.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def basic_engine():
4646
print("Stopped")
4747

4848

49-
def start_workflow(md, da, workflow_file_name) -> str:
49+
def start_workflow(md, da, workflow_file_name, variables) -> str:
5050
"""A convenience function to handle all the 'START' logic for a workflow.
5151
It is given the message dispatcher, data adapter, and the base-name of the
5252
workflow definition - i.e. the filename without the '.yaml' extension
@@ -72,7 +72,9 @@ def start_workflow(md, da, workflow_file_name) -> str:
7272
assert wfid
7373
print(f"Created workflow definition {wfid}")
7474
# 2.
75-
response = da.create_running_workflow(workflow_id=wfid, project_id=TEST_PROJECT_ID)
75+
response = da.create_running_workflow(
76+
workflow_id=wfid, project_id=TEST_PROJECT_ID, variables=variables
77+
)
7678
r_wfid = response["id"]
7779
assert r_wfid
7880
print(f"Created running workflow {r_wfid}")
@@ -122,7 +124,7 @@ def test_workflow_engine_example_two_step_nop(basic_engine):
122124
da, mq, md, _ = basic_engine
123125

124126
# Act
125-
r_wfid = start_workflow(md, da, "example-two-step-nop")
127+
r_wfid = start_workflow(md, da, "example-two-step-nop", {})
126128

127129
# Assert
128130
wait_for_workflow(da, mq, r_wfid)
@@ -141,7 +143,7 @@ def test_workflow_engine_example_nop_fail(basic_engine):
141143
da, mq, md, _ = basic_engine
142144

143145
# Act
144-
r_wfid = start_workflow(md, da, "example-nop-fail")
146+
r_wfid = start_workflow(md, da, "example-nop-fail", {})
145147

146148
# Assert
147149
wait_for_workflow(da, mq, r_wfid, expect_success=False)

workflow/workflow_abc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def create_running_workflow(
9797
*,
9898
workflow_id: str,
9999
project_id: str,
100+
variables: Dict[str, Any],
100101
) -> Dict[str, Any]:
101102
"""Create a RunningWorkflow Record (from a Workflow)"""
102103
# Should return:
@@ -120,6 +121,7 @@ def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
120121
# "success": false,
121122
# "workflow": {"id": "workflow-000"},
122123
# "project_id": "project-000",
124+
# "variables": {"x": 1, "y": 2},
123125
# }
124126
# }
125127

0 commit comments

Comments
 (0)