Skip to content

Commit bf66901

Browse files
author
Alan Christie
committed
style: Removed get workflow by name (and API fixes)
1 parent 170b270 commit bf66901

File tree

3 files changed

+49
-116
lines changed

3 files changed

+49
-116
lines changed

tests/test_test_api_adapter.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@ def test_get_workflow():
5454
assert wf["workflow"]["name"] == "blah"
5555

5656

57-
def test_get_workflow_by_name():
58-
# Arrange
59-
utaa = UnitTestWorkflowAPIAdapter()
60-
_ = utaa.create_workflow(workflow_definition={"name": "blah"})
61-
62-
# Act
63-
response = utaa.get_workflow_by_name(name="blah", version="1.0.0")
64-
65-
# Assert
66-
assert response["workflow"]["name"] == "blah"
67-
assert "id" in response
68-
69-
7057
def test_create_running_workflow():
7158
# Arrange
7259
utaa = UnitTestWorkflowAPIAdapter()
@@ -256,35 +243,6 @@ def test_get_running_workflow_step():
256243
assert rwfs["running_workflow"] == rwfid
257244

258245

259-
def test_get_running_workflow_steps():
260-
# Arrange
261-
utaa = UnitTestWorkflowAPIAdapter()
262-
response = utaa.create_workflow(workflow_definition={"name": "blah"})
263-
wfid = response["id"]
264-
response = utaa.create_running_workflow(
265-
user_id="dlister",
266-
workflow_id=wfid,
267-
project_id=TEST_PROJECT_ID,
268-
variables={},
269-
)
270-
rwfid = response["id"]
271-
response = utaa.create_running_workflow_step(
272-
running_workflow_id=rwfid, step="step-1"
273-
)
274-
rwfsid = response["id"]
275-
276-
# Act
277-
response = utaa.get_running_workflow_steps(running_workflow_id=rwfid)
278-
279-
# Assert
280-
assert response["count"] == 1
281-
rwfs = response["running_workflow_steps"][0]
282-
assert rwfs["id"] == rwfsid
283-
assert rwfs["running_workflow_step"]["step"] == "step-1"
284-
assert not rwfs["running_workflow_step"]["done"]
285-
assert rwfs["running_workflow_step"]["running_workflow"] == rwfid
286-
287-
288246
def test_create_instance():
289247
# Arrange
290248
utaa = UnitTestWorkflowAPIAdapter()

tests/wapi_adapter.py

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
from multiprocessing import Lock
2020
from pickle import Pickler, Unpickler
21-
from typing import Any, Dict, List, Optional
21+
from typing import Any
2222

2323
import yaml
2424

@@ -29,7 +29,7 @@
2929
os.path.dirname(__file__), "job-definitions", "job-definitions.yaml"
3030
)
3131
with open(_JOB_DEFINITION_FILE, "r", encoding="utf8") as jd_file:
32-
_JOB_DEFINITIONS: Dict[str, Any] = yaml.load(jd_file, Loader=yaml.FullLoader)
32+
_JOB_DEFINITIONS: dict[str, Any] = yaml.load(jd_file, Loader=yaml.FullLoader)
3333
assert _JOB_DEFINITIONS
3434

3535
# Table UUID formats
@@ -80,7 +80,7 @@ def __init__(self):
8080
Pickler(pickle_file).dump({})
8181
UnitTestWorkflowAPIAdapter.lock.release()
8282

83-
def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
83+
def create_workflow(self, *, workflow_definition: dict[str, Any]) -> dict[str, Any]:
8484
UnitTestWorkflowAPIAdapter.lock.acquire()
8585
with open(_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
8686
workflow = Unpickler(pickle_file).load()
@@ -95,34 +95,22 @@ def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
9595

9696
return {"id": workflow_definition_id}
9797

98-
def get_workflow(self, *, workflow_id: str) -> Dict[str, Any]:
98+
def get_workflow(self, *, workflow_id: str) -> dict[str, Any]:
9999
UnitTestWorkflowAPIAdapter.lock.acquire()
100100
with open(_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
101101
workflow = Unpickler(pickle_file).load()
102102
UnitTestWorkflowAPIAdapter.lock.release()
103103

104104
return {"workflow": workflow[workflow_id]} if workflow_id in workflow else {}
105105

106-
def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
107-
UnitTestWorkflowAPIAdapter.lock.acquire()
108-
with open(_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
109-
workflow = Unpickler(pickle_file).load()
110-
UnitTestWorkflowAPIAdapter.lock.release()
111-
112-
item = {}
113-
for wfid, value in workflow.items():
114-
if value["name"] == name:
115-
item = {"id": wfid, "workflow": value}
116-
return item
117-
118106
def create_running_workflow(
119107
self,
120108
*,
121109
user_id: str,
122110
workflow_id: str,
123111
project_id: str,
124-
variables: Dict[str, Any],
125-
) -> str:
112+
variables: dict[str, Any],
113+
) -> dict[str, Any]:
126114
assert user_id
127115
assert isinstance(variables, dict)
128116

@@ -149,13 +137,23 @@ def create_running_workflow(
149137

150138
return {"id": running_workflow_id}
151139

140+
def get_running_workflow(self, *, running_workflow_id: str) -> dict[str, Any]:
141+
UnitTestWorkflowAPIAdapter.lock.acquire()
142+
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
143+
running_workflow = Unpickler(pickle_file).load()
144+
UnitTestWorkflowAPIAdapter.lock.release()
145+
146+
if running_workflow_id not in running_workflow:
147+
return {}
148+
return {"running_workflow": running_workflow[running_workflow_id]}
149+
152150
def set_running_workflow_done(
153151
self,
154152
*,
155153
running_workflow_id: str,
156154
success: bool,
157-
error: Optional[int] = None,
158-
error_msg: Optional[str] = None,
155+
error: int | None = None,
156+
error_msg: str | None = None,
159157
) -> None:
160158
UnitTestWorkflowAPIAdapter.lock.acquire()
161159
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
@@ -171,19 +169,9 @@ def set_running_workflow_done(
171169
Pickler(pickle_file).dump(running_workflow)
172170
UnitTestWorkflowAPIAdapter.lock.release()
173171

174-
def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
175-
UnitTestWorkflowAPIAdapter.lock.acquire()
176-
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
177-
running_workflow = Unpickler(pickle_file).load()
178-
UnitTestWorkflowAPIAdapter.lock.release()
179-
180-
if running_workflow_id not in running_workflow:
181-
return {}
182-
return {"running_workflow": running_workflow[running_workflow_id]}
183-
184172
def create_running_workflow_step(
185173
self, *, running_workflow_id: str, step: str
186-
) -> str:
174+
) -> dict[str, Any]:
187175
UnitTestWorkflowAPIAdapter.lock.acquire()
188176
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
189177
running_workflow_step = Unpickler(pickle_file).load()
@@ -208,7 +196,7 @@ def create_running_workflow_step(
208196

209197
def get_running_workflow_step(
210198
self, *, running_workflow_step_id: str
211-
) -> Dict[str, Any]:
199+
) -> dict[str, Any]:
212200
UnitTestWorkflowAPIAdapter.lock.acquire()
213201
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
214202
running_workflow_step = Unpickler(pickle_file).load()
@@ -225,8 +213,8 @@ def set_running_workflow_step_done(
225213
*,
226214
running_workflow_step_id: str,
227215
success: bool,
228-
error: Optional[int] = None,
229-
error_msg: Optional[str] = None,
216+
error: int | None = None,
217+
error_msg: str | None = None,
230218
) -> None:
231219
UnitTestWorkflowAPIAdapter.lock.acquire()
232220
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
@@ -242,9 +230,7 @@ def set_running_workflow_step_done(
242230
Pickler(pickle_file).dump(running_workflow_step)
243231
UnitTestWorkflowAPIAdapter.lock.release()
244232

245-
def get_running_workflow_steps(
246-
self, *, running_workflow_id: str
247-
) -> List[Dict[str, Any]]:
233+
def get_running_workflow_steps(self, *, running_workflow_id: str) -> dict[str, Any]:
248234
UnitTestWorkflowAPIAdapter.lock.acquire()
249235
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
250236
running_workflow_step = Unpickler(pickle_file).load()
@@ -257,7 +243,7 @@ def get_running_workflow_steps(
257243
steps.append(item)
258244
return {"count": len(steps), "running_workflow_steps": steps}
259245

260-
def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
246+
def create_instance(self, *, running_workflow_step_id: str) -> dict[str, Any]:
261247
UnitTestWorkflowAPIAdapter.lock.acquire()
262248
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
263249
instances = Unpickler(pickle_file).load()
@@ -275,15 +261,15 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
275261

276262
return {"id": instance_id}
277263

278-
def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
264+
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
279265
UnitTestWorkflowAPIAdapter.lock.acquire()
280266
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
281267
instances = Unpickler(pickle_file).load()
282268
UnitTestWorkflowAPIAdapter.lock.release()
283269

284270
return {} if instance_id not in instances else instances[instance_id]
285271

286-
def create_task(self, *, instance_id: str) -> Dict[str, Any]:
272+
def create_task(self, *, instance_id: str) -> dict[str, Any]:
287273
UnitTestWorkflowAPIAdapter.lock.acquire()
288274
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
289275
tasks = Unpickler(pickle_file).load()
@@ -302,17 +288,15 @@ def create_task(self, *, instance_id: str) -> Dict[str, Any]:
302288

303289
return {"id": task_id}
304290

305-
def get_task(self, *, task_id: str) -> Dict[str, Any]:
291+
def get_task(self, *, task_id: str) -> dict[str, Any]:
306292
UnitTestWorkflowAPIAdapter.lock.acquire()
307293
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
308294
tasks = Unpickler(pickle_file).load()
309295
UnitTestWorkflowAPIAdapter.lock.release()
310296

311297
return {} if task_id not in tasks else tasks[task_id]
312298

313-
def get_job(
314-
self, *, collection: str, job: str, version: str
315-
) -> Optional[Dict[str, Any]]:
299+
def get_job(self, *, collection: str, job: str, version: str) -> dict[str, Any]:
316300
assert collection == _JOB_DEFINITIONS["collection"]
317301
assert job in _JOB_DEFINITIONS["jobs"]
318302
assert version

workflow/workflow_abc.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,7 @@ def get_workflow(
9797
# {
9898
# "workflow": <workflow>,
9999
# }
100-
101-
@abstractmethod
102-
def get_workflow_by_name(
103-
self,
104-
*,
105-
name: str,
106-
version: str,
107-
) -> dict[str, Any]:
108-
"""Get a Workflow Record by name"""
109-
# If present this should return:
110-
# {
111-
# "id": "workflow-00000000-0000-0000-0000-000000000001",
112-
# "workflow": <workflow>,
113-
# }
100+
# If not present an empty dictionary should be returned.
114101

115102
@abstractmethod
116103
def create_running_workflow(
@@ -127,18 +114,6 @@ def create_running_workflow(
127114
# "id": "r-workflow-00000000-0000-0000-0000-000000000001",
128115
# }
129116

130-
@abstractmethod
131-
def set_running_workflow_done(
132-
self,
133-
*,
134-
running_workflow_id: str,
135-
success: bool,
136-
error: int | None = None,
137-
error_msg: str | None = None,
138-
) -> None:
139-
"""Set the success value for a RunningWorkflow Record.
140-
If not successful an error code and message should be provided."""
141-
142117
@abstractmethod
143118
def get_running_workflow(self, *, running_workflow_id: str) -> dict[str, Any]:
144119
"""Get a RunningWorkflow Record"""
@@ -156,6 +131,19 @@ def get_running_workflow(self, *, running_workflow_id: str) -> dict[str, Any]:
156131
# "variables": {"x": 1, "y": 2},
157132
# }
158133
# }
134+
# If not present an empty dictionary should be returned.
135+
136+
@abstractmethod
137+
def set_running_workflow_done(
138+
self,
139+
*,
140+
running_workflow_id: str,
141+
success: bool,
142+
error: int | None = None,
143+
error_msg: str | None = None,
144+
) -> None:
145+
"""Set the success value for a RunningWorkflow Record.
146+
If not successful an error code and message should be provided."""
159147

160148
@abstractmethod
161149
def create_running_workflow_step(
@@ -186,6 +174,7 @@ def get_running_workflow_step(
186174
# "running_workflow": "r-workflow-00000000-0000-0000-0000-000000000001",
187175
# },
188176
# }
177+
# If not present an empty dictionary should be returned.
189178

190179
@abstractmethod
191180
def set_running_workflow_step_done(
@@ -200,9 +189,7 @@ def set_running_workflow_step_done(
200189
If not successful an error code and message should be provided."""
201190

202191
@abstractmethod
203-
def get_running_workflow_steps(
204-
self, *, running_workflow_id: str
205-
) -> list[dict[str, Any]]:
192+
def get_running_workflow_steps(self, *, running_workflow_id: str) -> dict[str, Any]:
206193
"""Gets all the RunningWorkflowStep Records (for a RunningWorkflow)"""
207194
# Should return:
208195
# {
@@ -221,6 +208,7 @@ def get_running_workflow_steps(
221208
# ...
222209
# ]
223210
# }
211+
# If there are not steps an empty dictionary should be returned and a count of 0
224212

225213
@abstractmethod
226214
def create_instance(self, running_workflow_step_id: str) -> dict[str, Any]:
@@ -239,6 +227,7 @@ def get_instance(self, *, instance_id: str) -> dict[str, Any]:
239227
# "running_workflow_step": "r-workflow-step-00000000-0000-0000-0000-000000000001",
240228
# [...],
241229
# }
230+
# If not present an empty dictionary should be returned.
242231

243232
@abstractmethod
244233
def create_task(self, instance_id: str) -> dict[str, Any]:
@@ -257,6 +246,7 @@ def get_task(self, *, task_id: str) -> dict[str, Any]:
257246
# "exit_code": 0,
258247
# [...],
259248
# }
249+
# If not present an empty dictionary should be returned.
260250

261251
@abstractmethod
262252
def get_job(
@@ -265,8 +255,9 @@ def get_job(
265255
collection: str,
266256
job: str,
267257
version: str,
268-
) -> dict[str, Any] | None:
258+
) -> dict[str, Any]:
269259
"""Get a Job"""
260+
# If not present an empty dictionary should be returned.
270261

271262

272263
class MessageDispatcher(ABC):

0 commit comments

Comments
 (0)