@@ -80,21 +80,6 @@ def __init__(self):
80
80
Pickler (pickle_file ).dump ({})
81
81
UnitTestWorkflowAPIAdapter .lock .release ()
82
82
83
- def create_workflow (self , * , workflow_definition : dict [str , Any ]) -> dict [str , Any ]:
84
- UnitTestWorkflowAPIAdapter .lock .acquire ()
85
- with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
86
- workflow = Unpickler (pickle_file ).load ()
87
-
88
- next_id : int = len (workflow ) + 1
89
- workflow_definition_id : str = _WORKFLOW_DEFINITION_ID_FORMAT .format (id = next_id )
90
- workflow [workflow_definition_id ] = workflow_definition
91
-
92
- with open (_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
93
- Pickler (pickle_file ).dump (workflow )
94
- UnitTestWorkflowAPIAdapter .lock .release ()
95
-
96
- return {"id" : workflow_definition_id }
97
-
98
83
def get_workflow (self , * , workflow_id : str ) -> dict [str , Any ]:
99
84
UnitTestWorkflowAPIAdapter .lock .acquire ()
100
85
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
@@ -103,40 +88,6 @@ def get_workflow(self, *, workflow_id: str) -> dict[str, Any]:
103
88
104
89
return {"workflow" : workflow [workflow_id ]} if workflow_id in workflow else {}
105
90
106
- def create_running_workflow (
107
- self ,
108
- * ,
109
- user_id : str ,
110
- workflow_id : str ,
111
- project_id : str ,
112
- variables : dict [str , Any ],
113
- ) -> dict [str , Any ]:
114
- assert user_id
115
- assert isinstance (variables , dict )
116
-
117
- UnitTestWorkflowAPIAdapter .lock .acquire ()
118
- with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
119
- running_workflow = Unpickler (pickle_file ).load ()
120
-
121
- next_id : int = len (running_workflow ) + 1
122
- running_workflow_id : str = _RUNNING_WORKFLOW_ID_FORMAT .format (id = next_id )
123
- record = {
124
- "user_id" : user_id ,
125
- "user_api_token" : "123456789" ,
126
- "done" : False ,
127
- "success" : False ,
128
- "workflow" : workflow_id ,
129
- "project_id" : project_id ,
130
- "variables" : variables ,
131
- }
132
- running_workflow [running_workflow_id ] = record
133
-
134
- with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
135
- Pickler (pickle_file ).dump (running_workflow )
136
- UnitTestWorkflowAPIAdapter .lock .release ()
137
-
138
- return {"id" : running_workflow_id }
139
-
140
91
def get_running_workflow (self , * , running_workflow_id : str ) -> dict [str , Any ]:
141
92
UnitTestWorkflowAPIAdapter .lock .acquire ()
142
93
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
@@ -251,14 +202,6 @@ def get_instance(self, *, instance_id: str) -> dict[str, Any]:
251
202
252
203
return {} if instance_id not in instances else instances [instance_id ]
253
204
254
- def get_task (self , * , task_id : str ) -> dict [str , Any ]:
255
- UnitTestWorkflowAPIAdapter .lock .acquire ()
256
- with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
257
- tasks = Unpickler (pickle_file ).load ()
258
- UnitTestWorkflowAPIAdapter .lock .release ()
259
-
260
- return {} if task_id not in tasks else tasks [task_id ]
261
-
262
205
def get_job (self , * , collection : str , job : str , version : str ) -> dict [str , Any ]:
263
206
assert collection == _JOB_DEFINITIONS ["collection" ]
264
207
assert job in _JOB_DEFINITIONS ["jobs" ]
@@ -270,9 +213,58 @@ def get_job(self, *, collection: str, job: str, version: str) -> dict[str, Any]:
270
213
response ["variables" ] = jd ["variables" ]
271
214
return response
272
215
273
- # Methods required for the UnitTestInstanceLauncher
216
+ # Methods required for the UnitTestInstanceLauncher and other (internal) logic
274
217
# but not exposed to (or required by) the Workflow Engine...
275
218
219
+ def create_workflow (self , * , workflow_definition : dict [str , Any ]) -> dict [str , Any ]:
220
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
221
+ with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
222
+ workflow = Unpickler (pickle_file ).load ()
223
+
224
+ next_id : int = len (workflow ) + 1
225
+ workflow_definition_id : str = _WORKFLOW_DEFINITION_ID_FORMAT .format (id = next_id )
226
+ workflow [workflow_definition_id ] = workflow_definition
227
+
228
+ with open (_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
229
+ Pickler (pickle_file ).dump (workflow )
230
+ UnitTestWorkflowAPIAdapter .lock .release ()
231
+
232
+ return {"id" : workflow_definition_id }
233
+
234
+ def create_running_workflow (
235
+ self ,
236
+ * ,
237
+ user_id : str ,
238
+ workflow_id : str ,
239
+ project_id : str ,
240
+ variables : dict [str , Any ],
241
+ ) -> dict [str , Any ]:
242
+ assert user_id
243
+ assert isinstance (variables , dict )
244
+
245
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
246
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
247
+ running_workflow = Unpickler (pickle_file ).load ()
248
+
249
+ next_id : int = len (running_workflow ) + 1
250
+ running_workflow_id : str = _RUNNING_WORKFLOW_ID_FORMAT .format (id = next_id )
251
+ record = {
252
+ "user_id" : user_id ,
253
+ "user_api_token" : "123456789" ,
254
+ "done" : False ,
255
+ "success" : False ,
256
+ "workflow" : workflow_id ,
257
+ "project_id" : project_id ,
258
+ "variables" : variables ,
259
+ }
260
+ running_workflow [running_workflow_id ] = record
261
+
262
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
263
+ Pickler (pickle_file ).dump (running_workflow )
264
+ UnitTestWorkflowAPIAdapter .lock .release ()
265
+
266
+ return {"id" : running_workflow_id }
267
+
276
268
def create_instance (self , * , running_workflow_step_id : str ) -> dict [str , Any ]:
277
269
UnitTestWorkflowAPIAdapter .lock .acquire ()
278
270
with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
0 commit comments