Skip to content

Commit fa57c9e

Browse files
GitHKAndrei Neagugiancarloromeo
authored
pydantic2 migration made integration tests green (#6719)
Co-authored-by: Andrei Neagu <[email protected]> Co-authored-by: Giancarlo Romeo <[email protected]>
1 parent 44f85bf commit fa57c9e

File tree

61 files changed

+226
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+226
-158
lines changed

packages/dask-task-models-library/src/dask_task_models_library/container_tasks/io.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
from contextlib import suppress
33
from pathlib import Path
4-
from typing import Any, TypeAlias, Union
4+
from typing import Annotated, Any, TypeAlias
55

66
from models_library.basic_regex import MIME_TYPE_RE
77
from models_library.generics import DictModel
@@ -84,15 +84,16 @@ class FileUrl(BaseModel):
8484
)
8585

8686

87-
PortValue: TypeAlias = Union[
88-
StrictBool,
89-
StrictInt,
90-
StrictFloat,
91-
StrictStr,
92-
FileUrl,
93-
list[Any],
94-
dict[str, Any],
95-
None,
87+
PortValue: TypeAlias = Annotated[
88+
StrictBool
89+
| StrictInt
90+
| StrictFloat
91+
| StrictStr
92+
| FileUrl
93+
| list[Any]
94+
| dict[str, Any]
95+
| None,
96+
Field(union_mode="left_to_right"),
9697
]
9798

9899

@@ -112,7 +113,9 @@ class TaskInputData(DictModel[ServicePortKey, PortValue]):
112113
)
113114

114115

115-
PortSchemaValue: TypeAlias = Union[PortSchema, FilePortSchema]
116+
PortSchemaValue: TypeAlias = Annotated[
117+
PortSchema | FilePortSchema, Field(union_mode="left_to_right")
118+
]
116119

117120

118121
class TaskOutputDataSchema(DictModel[ServicePortKey, PortSchemaValue]):

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ class ServiceUpdate(ServiceMetaDataEditable, ServiceAccessRights):
205205
class ServiceGet(
206206
ServiceMetaDataPublished, ServiceAccessRights, ServiceMetaDataEditable
207207
): # pylint: disable=too-many-ancestors
208-
owner: LowerCaseEmailStr | None
208+
owner: LowerCaseEmailStr | None = Field(
209+
description="None when the owner email cannot be found in the database"
210+
)
209211

210212
model_config = ConfigDict(
211213
extra="ignore",
@@ -230,7 +232,9 @@ class ServiceGetV2(BaseModel):
230232

231233
contact: LowerCaseEmailStr | None
232234
authors: list[Author] = Field(..., min_length=1)
233-
owner: LowerCaseEmailStr | None
235+
owner: LowerCaseEmailStr | None = Field(
236+
description="None when the owner email cannot be found in the database"
237+
)
234238

235239
inputs: ServiceInputsDict
236240
outputs: ServiceOutputsDict

packages/models-library/src/models_library/clusters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import auto
22
from pathlib import Path
3-
from typing import Final, Literal, Self, TypeAlias
3+
from typing import Annotated, Final, Literal, Self, TypeAlias
44

55
from pydantic import (
66
AnyUrl,
@@ -142,7 +142,9 @@ class BaseCluster(BaseModel):
142142
authentication: ClusterAuthentication = Field(
143143
..., description="Dask gateway authentication", discriminator="type"
144144
)
145-
access_rights: dict[GroupID, ClusterAccessRights] = Field(default_factory=dict)
145+
access_rights: Annotated[
146+
dict[GroupID, ClusterAccessRights], Field(default_factory=dict)
147+
]
146148

147149
_from_equivalent_enums = field_validator("type", mode="before")(
148150
create_enums_pre_validator(ClusterTypeInModel)

packages/pytest-simcore/src/pytest_simcore/docker_compose.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,37 @@ def testing_environ_vars(env_devel_file: Path) -> EnvVarsDict:
9494
# ensure we do not use the bucket of simcore or so
9595
env_devel["S3_BUCKET_NAME"] = "pytestbucket"
9696

97+
# ensure OpenTelemetry is not enabled
98+
env_devel |= {
99+
tracing_setting: "null"
100+
for tracing_setting in (
101+
"AGENT_TRACING",
102+
"API_SERVER_TRACING",
103+
"AUTOSCALING_TRACING",
104+
"CATALOG_TRACING",
105+
"CLUSTERS_KEEPER_TRACING",
106+
"DATCORE_ADAPTER_TRACING",
107+
"DIRECTOR_TRACING",
108+
"DIRECTOR_V2_TRACING",
109+
"DYNAMIC_SCHEDULER_TRACING",
110+
"EFS_GUARDIAN_TRACING",
111+
"INVITATIONS_TRACING",
112+
"PAYMENTS_TRACING",
113+
"RESOURCE_USAGE_TRACKER_TRACING",
114+
"STORAGE_TRACING",
115+
"WB_DB_EL_TRACING",
116+
"WB_GC_TRACING",
117+
"WEBSERVER_TRACING",
118+
)
119+
}
120+
97121
return {key: value for key, value in env_devel.items() if value is not None}
98122

99123

100124
@pytest.fixture(scope="module")
101125
def env_file_for_testing(
102126
temp_folder: Path,
103-
testing_environ_vars: dict[str, str],
127+
testing_environ_vars: EnvVarsDict,
104128
osparc_simcore_root_dir: Path,
105129
) -> Iterator[Path]:
106130
"""Dumps all the environment variables into an $(temp_folder)/.env.test file

packages/pytest-simcore/src/pytest_simcore/docker_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def jupyter_service(docker_registry: str, node_meta_schema: dict) -> dict[str, A
261261
)
262262

263263

264-
@pytest.fixture(scope="session", params=["2.0.4"])
264+
@pytest.fixture(scope="session", params=["2.0.7"])
265265
def dy_static_file_server_version(request: pytest.FixtureRequest):
266266
return request.param
267267

packages/pytest-simcore/src/pytest_simcore/helpers/httpx_calls_capture_parameters.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,19 @@ def regex_pattern(self) -> str:
6767
msg = "Current version cannot compute regex patterns in case of oneOf. Please go ahead and implement it yourself."
6868
raise NotImplementedError(msg)
6969
if self.anyOf:
70-
return "|".join([elm.regex_pattern for elm in self.anyOf])
70+
return "|".join(
71+
[
72+
elm.regex_pattern
73+
for elm in self.anyOf # pylint:disable=not-an-iterable
74+
]
75+
)
7176
if self.allOf:
72-
return "&".join([elm.regex_pattern for elm in self.allOf])
77+
return "&".join(
78+
[
79+
elm.regex_pattern
80+
for elm in self.allOf # pylint:disable=not-an-iterable
81+
]
82+
)
7383

7484
# now deal with non-recursive cases
7585
pattern: str | None = None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from collections.abc import Callable
2+
3+
from yarl import URL
4+
5+
6+
def replace_storage_endpoint(host: str, port: int) -> Callable[[str], str]:
7+
def _(url: str) -> str:
8+
url_obj = URL(url).with_host(host).with_port(port)
9+
return f"{url_obj}"
10+
11+
return _

packages/pytest-simcore/src/pytest_simcore/simcore_dask_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ async def dask_scheduler_service(
2727
)
2828
# override the port
2929
monkeypatch.setenv("DASK_SCHEDULER_PORT", f"{dask_scheduler_api_port}")
30-
return AnyUrl.build(
31-
scheme="tls", host=get_localhost_ip(), port=dask_scheduler_api_port
30+
url = AnyUrl.build(
31+
scheme="tls", host=get_localhost_ip(), port=int(dask_scheduler_api_port)
3232
)
33+
return f"{url}"
3334

3435

3536
@pytest.fixture

packages/pytest-simcore/src/pytest_simcore/simcore_storage_service.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
import tenacity
1111
from models_library.projects import ProjectID
1212
from models_library.projects_nodes_io import NodeID, SimcoreS3FileID
13-
from pydantic import AnyUrl, TypeAdapter
13+
from pydantic import TypeAdapter
1414
from pytest_mock import MockerFixture
1515
from servicelib.minio_utils import ServiceRetryPolicyUponInitialization
1616
from yarl import URL
1717

1818
from .helpers.docker import get_service_published_port
1919
from .helpers.host import get_localhost_ip
20+
from .helpers.storage import replace_storage_endpoint
2021

2122

2223
@pytest.fixture(scope="module")
@@ -45,22 +46,12 @@ async def storage_service(
4546
) -> URL:
4647
await wait_till_storage_responsive(storage_endpoint)
4748

48-
def correct_ip(url: AnyUrl):
49-
assert storage_endpoint.host is not None
50-
assert storage_endpoint.port is not None
51-
52-
return AnyUrl.build(
53-
scheme=url.scheme,
54-
host=storage_endpoint.host,
55-
port=f"{storage_endpoint.port}",
56-
path=url.path,
57-
query=url.query,
58-
)
59-
6049
# NOTE: Mock to ensure container IP agrees with host IP when testing
50+
assert storage_endpoint.host is not None
51+
assert storage_endpoint.port is not None
6152
mocker.patch(
6253
"simcore_sdk.node_ports_common._filemanager._get_https_link_if_storage_secure",
63-
correct_ip,
54+
replace_storage_endpoint(storage_endpoint.host, storage_endpoint.port),
6455
)
6556

6657
return storage_endpoint

packages/service-library/src/servicelib/aiohttp/long_running_tasks/_server.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
from aiohttp import web
88
from common_library.json_serialization import json_dumps
9-
from common_library.pydantic_networks_extension import AnyHttpUrlLegacy
10-
from pydantic import PositiveFloat, TypeAdapter
9+
from pydantic import AnyHttpUrl, PositiveFloat, TypeAdapter
1110

1211
from ...aiohttp import status
1312
from ...long_running_tasks._models import TaskGet
@@ -68,13 +67,13 @@ async def start_long_running_task(
6867
ip_addr, port = request_.transport.get_extra_info(
6968
"sockname"
7069
) # https://docs.python.org/3/library/asyncio-protocol.html#asyncio.BaseTransport.get_extra_info
71-
status_url = TypeAdapter(AnyHttpUrlLegacy).validate_python(
70+
status_url = TypeAdapter(AnyHttpUrl).validate_python(
7271
f"http://{ip_addr}:{port}{request_.app.router['get_task_status'].url_for(task_id=task_id)}" # NOSONAR
7372
)
74-
result_url = TypeAdapter(AnyHttpUrlLegacy).validate_python(
73+
result_url = TypeAdapter(AnyHttpUrl).validate_python(
7574
f"http://{ip_addr}:{port}{request_.app.router['get_task_result'].url_for(task_id=task_id)}" # NOSONAR
7675
)
77-
abort_url = TypeAdapter(AnyHttpUrlLegacy).validate_python(
76+
abort_url = TypeAdapter(AnyHttpUrl).validate_python(
7877
f"http://{ip_addr}:{port}{request_.app.router['cancel_and_delete_task'].url_for(task_id=task_id)}" # NOSONAR
7978
)
8079
task_get = TaskGet(

0 commit comments

Comments
 (0)