66# pylint: disable=unused-variable
77# pylint:disable=too-many-positional-arguments
88
9- import datetime
9+ import datetime as dt
1010import json
1111import re
1212import urllib .parse
2323import respx
2424from faker import Faker
2525from fastapi import FastAPI , status
26+ from models_library .api_schemas_catalog .services import ServiceGet
2627from models_library .api_schemas_clusters_keeper .ec2_instances import EC2InstanceTypeGet
2728from models_library .api_schemas_directorv2 .comp_tasks import (
2829 ComputationCreate ,
3334 PricingPlanGet ,
3435 PricingUnitGet ,
3536)
36- from models_library .basic_types import VersionStr
3737from models_library .clusters import DEFAULT_CLUSTER_ID , Cluster , ClusterID
3838from models_library .projects import ProjectAtDB
3939from models_library .projects_nodes import NodeID , NodeState
@@ -111,24 +111,24 @@ def fake_service_details(mocks_dir: Path) -> ServiceMetaDataPublished:
111111
112112@pytest .fixture
113113def fake_service_extras () -> ServiceExtras :
114- extra_example = ServiceExtras .model_config ["json_schema_extra" ]["examples" ][2 ]
115- random_extras = ServiceExtras (** extra_example )
114+ extra_example = ServiceExtras .model_config ["json_schema_extra" ]["examples" ][2 ] # type: ignore
115+ random_extras = ServiceExtras (** extra_example ) # type: ignore
116116 assert random_extras is not None
117117 return random_extras
118118
119119
120120@pytest .fixture
121121def fake_service_resources () -> ServiceResourcesDict :
122122 return TypeAdapter (ServiceResourcesDict ).validate_python (
123- ServiceResourcesDictHelpers .model_config ["json_schema_extra" ]["examples" ][0 ],
123+ ServiceResourcesDictHelpers .model_config ["json_schema_extra" ]["examples" ][0 ], # type: ignore
124124 )
125125
126126
127127@pytest .fixture
128128def fake_service_labels () -> dict [str , Any ]:
129- return choice (
130- SimcoreServiceLabels .model_config ["json_schema_extra" ]["examples" ]
131- ) # noqa: S311
129+ return choice ( # noqa: S311
130+ SimcoreServiceLabels .model_config ["json_schema_extra" ]["examples" ] # type: ignore
131+ )
132132
133133
134134@pytest .fixture
@@ -149,7 +149,9 @@ def mocked_director_service_fcts(
149149 r"/services/simcore%2Fservices%2F(comp|dynamic|frontend)%2F[^/]+/\d+.\d+.\d+$"
150150 ),
151151 name = "get_service" ,
152- ).respond (json = {"data" : [fake_service_details .model_dump (mode = "json" , by_alias = True )]})
152+ ).respond (
153+ json = {"data" : [fake_service_details .model_dump (mode = "json" , by_alias = True )]}
154+ )
153155 respx_mock .get (
154156 re .compile (
155157 r"/services/simcore%2Fservices%2F(comp|dynamic|frontend)%2F[^/]+/\d+.\d+.\d+/labels"
@@ -162,7 +164,9 @@ def mocked_director_service_fcts(
162164 r"/service_extras/(simcore)%2F(services)%2F(comp|dynamic|frontend)%2F.+/(.+)"
163165 ),
164166 name = "get_service_extras" ,
165- ).respond (json = {"data" : fake_service_extras .model_dump (mode = "json" , by_alias = True )})
167+ ).respond (
168+ json = {"data" : fake_service_extras .model_dump (mode = "json" , by_alias = True )}
169+ )
166170
167171 yield respx_mock
168172
@@ -184,7 +188,7 @@ def _mocked_services_details(
184188 return httpx .Response (
185189 200 ,
186190 json = jsonable_encoder (
187- fake_service_details .copy (
191+ fake_service_details .model_copy (
188192 update = {
189193 "key" : urllib .parse .unquote (service_key ),
190194 "version" : service_version ,
@@ -225,19 +229,30 @@ def mocked_catalog_service_fcts_deprecated(
225229 def _mocked_services_details (
226230 request , service_key : str , service_version : str
227231 ) -> httpx .Response :
232+ data_published = fake_service_details .model_copy (
233+ update = {
234+ "key" : urllib .parse .unquote (service_key ),
235+ "version" : service_version ,
236+ "deprecated" : (
237+ dt .datetime .now (tz = dt .UTC ) - dt .timedelta (days = 1 )
238+ ).isoformat (),
239+ }
240+ ).model_dump (by_alias = True )
241+
242+ deprecated = {
243+ "deprecated" : (
244+ dt .datetime .now (tz = dt .UTC ) - dt .timedelta (days = 1 )
245+ ).isoformat ()
246+ }
247+
248+ data = {** ServiceGet .model_config ["json_schema_extra" ]["examples" ][0 ], ** data_published , ** deprecated } # type: ignore
249+
250+ payload = ServiceGet .model_validate (data )
251+
228252 return httpx .Response (
229- 200 ,
253+ httpx . codes . OK ,
230254 json = jsonable_encoder (
231- fake_service_details .copy (
232- update = {
233- "key" : urllib .parse .unquote (service_key ),
234- "version" : service_version ,
235- "deprecated" : (
236- datetime .datetime .now (tz = datetime .UTC )
237- - datetime .timedelta (days = 1 )
238- ).isoformat (),
239- }
240- ),
255+ payload ,
241256 by_alias = True ,
242257 ),
243258 )
@@ -470,7 +485,6 @@ def project_nodes_overrides(request: pytest.FixtureRequest) -> dict[str, Any]:
470485 return request .param
471486
472487
473- @pytest .mark .testit
474488async def test_create_computation_with_wallet (
475489 minimal_configuration : None ,
476490 mocked_director_service_fcts : respx .MockRouter ,
@@ -618,8 +632,8 @@ async def test_create_computation_with_wallet_with_invalid_pricing_unit_name_rai
618632@pytest .mark .parametrize (
619633 "default_pricing_plan" ,
620634 [
621- PricingPlanGet .construct (
622- ** PricingPlanGet .model_config ["json_schema_extra" ]["examples" ][0 ]
635+ PricingPlanGet .model_construct (
636+ ** PricingPlanGet .model_config ["json_schema_extra" ]["examples" ][0 ] # type: ignore
623637 )
624638 ],
625639)
0 commit comments