2020functionalities for the entrypoint entity. The tests ensure that the entrypoints can be
2121registered, renamed, deleted, and locked/unlocked as expected through the REST API.
2222"""
23+
2324import textwrap
2425from http import HTTPStatus
2526from typing import Any
2829
2930from dioptra .client .base import DioptraResponseProtocol
3031from dioptra .client .client import DioptraClient
31- from dioptra .restapi .routes import V1_ROOT , V1_WORKFLOWS_ROUTE
3232
3333# -- Actions ---------------------------------------------------------------------------
3434
@@ -54,7 +54,7 @@ def validate_entrypoint_workflow(
5454 return dioptra_client .workflows .validate_entrypoint (
5555 task_graph = task_graph ,
5656 plugins = plugin_ids ,
57- entrypoint_parameters = entrypoint_parameters
57+ entrypoint_parameters = entrypoint_parameters ,
5858 )
5959
6060
@@ -63,10 +63,11 @@ def validate_entrypoint_workflow(
6363
6464def assert_entrypoint_workflow_is_valid (
6565 dioptra_client : DioptraClient [DioptraResponseProtocol ],
66+ group_id : int ,
6667 task_graph : str ,
67- plugin_ids : list [int ],
68+ plugins : list [int ],
6869 entrypoint_parameters : list [dict [str , Any ]],
69- ) -> None :
70+ ) -> None :
7071 """Asserts that the entrypoint workflow yaml is valid.
7172
7273 Args:
@@ -75,19 +76,20 @@ def assert_entrypoint_workflow_is_valid(
7576 plugin_ids (list[int]): The ids of plugins defined in the task graph.
7677 entrypoint_parameters (list[dict[str, Any]]): The parmeters defined in the task graph.
7778 """
78- response = validate_entrypoint_workflow (
79- dioptra_client ,
79+ response = dioptra_client . workflows . validate_entrypoint (
80+ group_id = group_id ,
8081 task_graph = task_graph ,
81- plugin_ids = plugin_ids ,
82+ plugins = plugins ,
8283 entrypoint_parameters = entrypoint_parameters ,
8384 )
84- assert response .status_code == HTTPStatus .OK and response .json ()[' valid' ] == True
85+ assert response .status_code == HTTPStatus .OK and response .json ()[" valid" ]
8586
8687
8788def assert_entrypoint_workflow_has_errors (
8889 dioptra_client : DioptraClient [DioptraResponseProtocol ],
90+ group_id : int ,
8991 task_graph : str ,
90- plugin_ids : list [int ],
92+ plugins : list [int ],
9193 entrypoint_parameters : list [dict [str , Any ]],
9294) -> None :
9395 """Asserts that the entrypoint workflow yaml is invalid.
@@ -98,13 +100,18 @@ def assert_entrypoint_workflow_has_errors(
98100 plugin_ids (list[int]): The ids of plugins defined in the task graph.
99101 entrypoint_parameters (list[dict[str, Any]]): The parmeters defined in the task graph.
100102 """
101- response = validate_entrypoint_workflow (
102- dioptra_client ,
103+ response = dioptra_client . workflows . validate_entrypoint (
104+ group_id = group_id ,
103105 task_graph = task_graph ,
104- plugin_ids = plugin_ids ,
106+ plugins = plugins ,
105107 entrypoint_parameters = entrypoint_parameters ,
106108 )
107- assert response .status_code == 422
109+ assert response .status_code == HTTPStatus .UNPROCESSABLE_ENTITY and response .json ()[
110+ "message"
111+ ] == (
112+ f"{ HTTPStatus .UNPROCESSABLE_ENTITY .phrase } - The proposed inputs for the "
113+ "entrypoint are invalid."
114+ )
108115
109116
110117# -- Tests -----------------------------------------------------------------------------
@@ -119,7 +126,7 @@ def test_entrypoint_workflow_validation(
119126
120127 Args:
121128 dioptra_client (DioptraClient): The Dioptra client.
122- db (SQLAlchemy): The entity database.
129+ db (SQLAlchemy): The entity database.
123130 auth_account (dict[str, Any]): The default authorized user account.
124131 """
125132 plugin_response = dioptra_client .plugins .create (
@@ -130,7 +137,7 @@ def test_entrypoint_workflow_validation(
130137
131138 plugin_file_contents = textwrap .dedent (
132139 """"from dioptra import pyplugs
133-
140+
134141 @pyplugs.register
135142 def hello_world(name: str) -> str:
136143 return f'Hello, {name}!'"
@@ -156,12 +163,12 @@ def hello_world(name: str) -> str:
156163 },
157164 ]
158165
159- plugin_file_response = dioptra_client .plugins .files .create (
166+ _ = dioptra_client .plugins .files .create (
160167 plugin_id = plugin_response ["id" ],
161168 filename = "tasks.py" ,
162169 description = "The task plugin file for hello world." ,
163170 contents = plugin_file_contents ,
164- tasks = plugin_file_tasks ,
171+ tasks = plugin_file_tasks ,
165172 ).json ()
166173
167174 task_graph = textwrap .dedent (
@@ -172,18 +179,19 @@ def hello_world(name: str) -> str:
172179 """
173180 )
174181
175- plugin_ids = [plugin_response ["id" ]]
182+ plugins = [plugin_response ["id" ]]
176183 entrypoint_parameters = [
177184 {
178- "name" : "name" ,
185+ "name" : "name" ,
179186 "defaultValue" : "User" ,
180187 "parameterType" : "string" ,
181188 },
182189 ]
183190 assert_entrypoint_workflow_is_valid (
184191 dioptra_client ,
192+ group_id = auth_account ["default_group_id" ],
185193 task_graph = task_graph ,
186- plugin_ids = plugin_ids ,
194+ plugins = plugins ,
187195 entrypoint_parameters = entrypoint_parameters ,
188196 )
189197
@@ -197,7 +205,7 @@ def test_entrypoint_workflow_validation_has_error(
197205
198206 Args:
199207 dioptra_client (DioptraClient): The Dioptra client.
200- db (SQLAlchemy): The entity database.
208+ db (SQLAlchemy): The entity database.
201209 auth_account (dict[str, Any]): The default authorized user account.
202210 """
203211 plugin_response = dioptra_client .plugins .create (
@@ -208,7 +216,7 @@ def test_entrypoint_workflow_validation_has_error(
208216
209217 plugin_file_contents = textwrap .dedent (
210218 """"from dioptra import pyplugs
211-
219+
212220 @pyplugs.register
213221 def hello_world(name: str) -> str:
214222 return f'Hello, {name}!'"
@@ -234,12 +242,12 @@ def hello_world(name: str) -> str:
234242 },
235243 ]
236244
237- plugin_file_response = dioptra_client .plugins .files .create (
245+ _ = dioptra_client .plugins .files .create (
238246 plugin_id = plugin_response ["id" ],
239247 filename = "tasks.py" ,
240248 description = "The task plugin file for hello world." ,
241249 contents = plugin_file_contents ,
242- tasks = plugin_file_tasks ,
250+ tasks = plugin_file_tasks ,
243251 ).json ()
244252
245253 task_graph = textwrap .dedent (
@@ -248,20 +256,21 @@ def hello_world(name: str) -> str:
248256 hello_wrld:
249257 name: $name
250258 """
251- ) # task graph is wrong, hello_wrld is not the task plugin
259+ ) # task graph is wrong, hello_wrld is not the task plugin
260+
261+ plugins = [plugin_response ["id" ]]
252262
253- plugin_ids = [plugin_response ["id" ]]
254-
255263 entrypoint_parameters = [
256264 {
257- "name" : "name" ,
265+ "name" : "name" ,
258266 "defaultValue" : "User" ,
259267 "parameterType" : "string" ,
260268 },
261269 ]
262270 assert_entrypoint_workflow_has_errors (
263271 dioptra_client ,
272+ group_id = auth_account ["default_group_id" ],
264273 task_graph = task_graph ,
265- plugin_ids = plugin_ids ,
274+ plugins = plugins ,
266275 entrypoint_parameters = entrypoint_parameters ,
267- )
276+ )
0 commit comments