Skip to content

Commit 4c53a12

Browse files
authored
♻️ New fakes in dev/catalog/service (#6012)
1 parent 2607824 commit 4c53a12

File tree

3 files changed

+177
-47
lines changed
  • packages/models-library/src/models_library
  • services/web/server/src/simcore_service_webserver/catalog

3 files changed

+177
-47
lines changed

packages/models-library/src/models_library/api_schemas_catalog/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Config:
105105
}
106106
},
107107
"owner": "[email protected]",
108-
}
108+
},
109109
}
110110

111111

packages/models-library/src/models_library/api_schemas_webserver/catalog.py

Lines changed: 171 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from copy import deepcopy
21
from typing import Any, ClassVar, TypeAlias
32

43
from pydantic import Extra, Field
@@ -100,18 +99,137 @@ class Config(_BaseCommonApiExtension.Config):
10099
ServiceOutputsGetDict: TypeAlias = dict[ServicePortKey, ServiceOutputGet]
101100

102101

103-
_EXAMPLE: dict[str, Any] = deepcopy(
104-
api_schemas_catalog_services.ServiceGet.Config.schema_extra["example"]
105-
)
106-
_EXAMPLE.update(
107-
{
102+
_EXAMPLE_FILEPICKER: dict[str, Any] = {
103+
**api_schemas_catalog_services.ServiceGet.Config.schema_extra["example"],
104+
**{
108105
"inputs": {
109106
f"input{i}": example
110107
for i, example in enumerate(ServiceInputGet.Config.schema_extra["examples"])
111108
},
112109
"outputs": {"outFile": ServiceOutputGet.Config.schema_extra["example"]},
113-
}
114-
)
110+
},
111+
}
112+
113+
114+
_EXAMPLE_SLEEPER: dict[str, Any] = {
115+
"name": "sleeper",
116+
"thumbnail": None,
117+
"description": "A service which awaits for time to pass, two times.",
118+
"classifiers": [],
119+
"quality": {},
120+
"accessRights": {"1": {"execute_access": True, "write_access": False}},
121+
"key": "simcore/services/comp/itis/sleeper",
122+
"version": "2.2.1",
123+
"version_display": "2 Xtreme",
124+
"integration-version": "1.0.0",
125+
"type": "computational",
126+
"authors": [
127+
{
128+
"name": "Author Bar",
129+
"email": "[email protected]",
130+
"affiliation": "ACME",
131+
},
132+
],
133+
"contact": "[email protected]",
134+
"inputs": {
135+
"input_1": {
136+
"displayOrder": 1,
137+
"label": "File with int number",
138+
"description": "Pick a file containing only one integer",
139+
"type": "data:text/plain",
140+
"fileToKeyMap": {"single_number.txt": "input_1"},
141+
"keyId": "input_1",
142+
},
143+
"input_2": {
144+
"unitLong": "second",
145+
"unitShort": "s",
146+
"label": "Sleep interval",
147+
"description": "Choose an amount of time to sleep in range [0:]",
148+
"keyId": "input_2",
149+
"displayOrder": 2,
150+
"type": "ref_contentSchema",
151+
"contentSchema": {
152+
"title": "Sleep interval",
153+
"type": "integer",
154+
"x_unit": "second",
155+
"minimum": 0,
156+
},
157+
"defaultValue": 2,
158+
},
159+
"input_3": {
160+
"displayOrder": 3,
161+
"label": "Fail after sleep",
162+
"description": "If set to true will cause service to fail after it sleeps",
163+
"type": "boolean",
164+
"defaultValue": False,
165+
"keyId": "input_3",
166+
},
167+
"input_4": {
168+
"unitLong": "meter",
169+
"unitShort": "m",
170+
"label": "Distance to bed",
171+
"description": "It will first walk the distance to bed",
172+
"keyId": "input_4",
173+
"displayOrder": 4,
174+
"type": "ref_contentSchema",
175+
"contentSchema": {
176+
"title": "Distance to bed",
177+
"type": "integer",
178+
"x_unit": "meter",
179+
},
180+
"defaultValue": 0,
181+
},
182+
"input_5": {
183+
"unitLong": "byte",
184+
"unitShort": "B",
185+
"label": "Dream (or nightmare) of the night",
186+
"description": "Defines the size of the dream that will be generated [0:]",
187+
"keyId": "input_5",
188+
"displayOrder": 5,
189+
"type": "ref_contentSchema",
190+
"contentSchema": {
191+
"title": "Dream of the night",
192+
"type": "integer",
193+
"x_unit": "byte",
194+
"minimum": 0,
195+
},
196+
"defaultValue": 0,
197+
},
198+
},
199+
"outputs": {
200+
"output_1": {
201+
"displayOrder": 1,
202+
"label": "File containing one random integer",
203+
"description": "Integer is generated in range [1-9]",
204+
"type": "data:text/plain",
205+
"fileToKeyMap": {"single_number.txt": "output_1"},
206+
"keyId": "output_1",
207+
},
208+
"output_2": {
209+
"unitLong": "second",
210+
"unitShort": "s",
211+
"label": "Random sleep interval",
212+
"description": "Interval is generated in range [1-9]",
213+
"keyId": "output_2",
214+
"displayOrder": 2,
215+
"type": "ref_contentSchema",
216+
"contentSchema": {
217+
"title": "Random sleep interval",
218+
"type": "integer",
219+
"x_unit": "second",
220+
},
221+
},
222+
"output_3": {
223+
"displayOrder": 3,
224+
"label": "Dream output",
225+
"description": "Contains some random data representing a dream",
226+
"type": "data:text/plain",
227+
"fileToKeyMap": {"dream.txt": "output_3"},
228+
"keyId": "output_3",
229+
},
230+
},
231+
"owner": "[email protected]",
232+
}
115233

116234

117235
class ServiceGet(api_schemas_catalog_services.ServiceGet):
@@ -124,7 +242,7 @@ class ServiceGet(api_schemas_catalog_services.ServiceGet):
124242
)
125243

126244
class Config(OutputSchema.Config):
127-
schema_extra: ClassVar[dict[str, Any]] = {"example": _EXAMPLE}
245+
schema_extra: ClassVar[dict[str, Any]] = {"example": _EXAMPLE_FILEPICKER}
128246

129247

130248
class ServiceUpdate(api_schemas_catalog_services.ServiceUpdate):
@@ -148,39 +266,51 @@ class DEVServiceGet(ServiceGet):
148266

149267
class Config(OutputSchema.Config):
150268
schema_extra: ClassVar[dict[str, Any]] = {
151-
"example": {
152-
**_EXAMPLE, # 1.0.0
153-
"history": [
154-
{
155-
"version": "1.0.5",
156-
"version_display": "Summer Release",
157-
"release_date": "2024-07-20T15:00:00",
158-
},
159-
{
160-
"version": _EXAMPLE["version"],
161-
"compatibility": {
162-
"can_update_to": "1.0.5",
269+
"examples": [
270+
{
271+
**_EXAMPLE_SLEEPER, # v2.2.1 (latest)
272+
"history": [
273+
{
274+
"version": _EXAMPLE_SLEEPER["version"],
275+
"version_display": "Summer Release",
276+
"release_date": "2024-07-20T15:00:00",
163277
},
164-
},
165-
{"version": "0.9.11"},
166-
{"version": "0.9.10"},
167-
{
168-
"version": "0.9.8",
169-
"compatibility": {
170-
"can_update_to": "0.9.10",
278+
{
279+
"version": "2.0.0",
280+
"compatibility": {
281+
"can_update_to": _EXAMPLE_SLEEPER["version"],
282+
},
171283
},
172-
},
173-
{
174-
"version": "0.9.1",
175-
"version_display": "Matterhorn",
176-
"release_date": "2024-01-20T18:49:17",
177-
"compatibility": {
178-
"can_update_to": "0.9.10",
284+
{"version": "0.9.11"},
285+
{"version": "0.9.10"},
286+
{
287+
"version": "0.9.8",
288+
"compatibility": {
289+
"can_update_to": "0.9.11",
290+
},
179291
},
180-
},
181-
{"version": "0.9.0"},
182-
{"version": "0.8.0"},
183-
{"version": "0.1.0"},
184-
],
185-
}
292+
{
293+
"version": "0.9.1",
294+
"version_display": "Matterhorn",
295+
"release_date": "2024-01-20T18:49:17",
296+
"compatibility": {
297+
"can_update_to": "0.9.11",
298+
},
299+
},
300+
{"version": "0.9.0"},
301+
{"version": "0.8.0"},
302+
{"version": "0.1.0"},
303+
],
304+
},
305+
{
306+
**_EXAMPLE_FILEPICKER,
307+
"history": [
308+
{
309+
"version": _EXAMPLE_FILEPICKER["version"],
310+
"version_display": "Odei Release",
311+
"release_date": "2025-03-25T00:00:00",
312+
}
313+
],
314+
},
315+
]
186316
}

services/web/server/src/simcore_service_webserver/catalog/_handlers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ async def dev_list_services_latest(request: Request):
8989
assert query_params # nosec
9090

9191
_logger.debug("Moking response for %s...", request)
92-
got = [
93-
parse_obj_as(DEVServiceGet, DEVServiceGet.Config.schema_extra["example"]),
94-
]
92+
got = parse_obj_as(
93+
list[DEVServiceGet], DEVServiceGet.Config.schema_extra["examples"]
94+
)
9595

9696
return envelope_json_response(
9797
got[query_params.offset : query_params.offset + query_params.limit]
@@ -113,7 +113,7 @@ async def dev_get_service(request: Request):
113113
assert path_params # nosec
114114

115115
_logger.debug("Moking response for %s...", request)
116-
got = parse_obj_as(DEVServiceGet, DEVServiceGet.Config.schema_extra["example"])
116+
got = parse_obj_as(DEVServiceGet, DEVServiceGet.Config.schema_extra["examples"][0])
117117
got.version = path_params.service_version
118118
got.key = path_params.service_key
119119

@@ -137,7 +137,7 @@ async def dev_update_service(request: Request):
137137
assert update # nosec
138138

139139
_logger.debug("Moking response for %s...", request)
140-
got = parse_obj_as(DEVServiceGet, DEVServiceGet.Config.schema_extra["example"])
140+
got = parse_obj_as(DEVServiceGet, DEVServiceGet.Config.schema_extra["examples"][0])
141141
got.version = path_params.service_version
142142
got.key = path_params.service_key
143143
updated = got.copy(update=update.dict(exclude_unset=True))

0 commit comments

Comments
 (0)