Skip to content

Commit 5c6661d

Browse files
Merge branch 'master' into is7563/clean-export-data-tasks-once-really-consumed
2 parents 9b7b15c + 3880aff commit 5c6661d

File tree

86 files changed

+1991
-1008
lines changed

Some content is hidden

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

86 files changed

+1991
-1008
lines changed

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

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Any, Literal
1+
from typing import Annotated, Any, Literal
22

33
from pydantic import BaseModel, ConfigDict, Field
4+
from pydantic.config import JsonDict
45

56
from ..basic_regex import PUBLIC_VARIABLE_NAME_RE
67
from ..services import ServiceInput, ServiceOutput
@@ -10,42 +11,65 @@
1011
update_schema_doc,
1112
)
1213

13-
PortKindStr = Literal["input", "output"]
14-
1514

1615
class ServicePortGet(BaseModel):
17-
key: str = Field(
18-
...,
19-
description="port identifier name",
20-
pattern=PUBLIC_VARIABLE_NAME_RE,
21-
title="Key name",
22-
)
23-
kind: PortKindStr
16+
key: Annotated[
17+
str,
18+
Field(
19+
description="Port identifier name",
20+
pattern=PUBLIC_VARIABLE_NAME_RE,
21+
title="Key name",
22+
),
23+
]
24+
kind: Literal["input", "output"]
2425
content_media_type: str | None = None
25-
content_schema: dict[str, Any] | None = Field(
26-
None,
27-
description="jsonschema for the port's value. SEE https://json-schema.org/understanding-json-schema/",
28-
)
29-
model_config = ConfigDict(
30-
json_schema_extra={
31-
"example": {
32-
"key": "input_1",
33-
"kind": "input",
34-
"content_schema": {
35-
"title": "Sleep interval",
36-
"type": "integer",
37-
"x_unit": "second",
38-
"minimum": 0,
39-
"maximum": 5,
40-
},
41-
}
26+
content_schema: Annotated[
27+
dict[str, Any] | None,
28+
Field(
29+
description="jsonschema for the port's value. SEE https://json-schema.org/understanding-json-schema/",
30+
),
31+
] = None
32+
33+
@staticmethod
34+
def _update_json_schema_extra(schema: JsonDict) -> None:
35+
example_input: dict[str, Any] = {
36+
"key": "input_1",
37+
"kind": "input",
38+
"content_schema": {
39+
"title": "Sleep interval",
40+
"type": "integer",
41+
"x_unit": "second",
42+
"minimum": 0,
43+
"maximum": 5,
44+
},
4245
}
46+
schema.update(
47+
{
48+
"example": example_input,
49+
"examples": [
50+
example_input,
51+
{
52+
"key": "output_1",
53+
"kind": "output",
54+
"content_media_type": "text/plain",
55+
"content_schema": {
56+
"type": "string",
57+
"title": "File containing one random integer",
58+
"description": "Integer is generated in range [1-9]",
59+
},
60+
},
61+
],
62+
}
63+
)
64+
65+
model_config = ConfigDict(
66+
json_schema_extra=_update_json_schema_extra,
4367
)
4468

4569
@classmethod
46-
def from_service_io(
70+
def from_domain_model(
4771
cls,
48-
kind: PortKindStr,
72+
kind: Literal["input", "output"],
4973
key: str,
5074
port: ServiceInput | ServiceOutput,
5175
) -> "ServicePortGet":

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class BaseServiceIOModel(BaseModel):
3030
Base class for service input/outputs
3131
"""
3232

33-
## management
34-
3533
### human readable descriptors
3634
display_order: float | None = Field(
3735
None,

packages/models-library/tests/test_api_schemas_catalog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_service_port_with_file():
2121
}
2222
)
2323

24-
port = ServicePortGet.from_service_io("input", "input_1", io).model_dump(
24+
port = ServicePortGet.from_domain_model("input", "input_1", io).model_dump(
2525
exclude_unset=True
2626
)
2727

@@ -49,7 +49,7 @@ def test_service_port_with_boolean():
4949
}
5050
)
5151

52-
port = ServicePortGet.from_service_io("input", "input_1", io).model_dump(
52+
port = ServicePortGet.from_domain_model("input", "input_1", io).model_dump(
5353
exclude_unset=True
5454
)
5555

packages/postgres-database/src/simcore_postgres_database/utils_user_preferences.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from typing import Any
22

33
import sqlalchemy as sa
4-
from aiopg.sa.connection import SAConnection
54
from sqlalchemy.dialects.postgresql import insert as pg_insert
5+
from sqlalchemy.ext.asyncio import AsyncConnection
66

77
from .models.user_preferences import (
88
user_preferences_frontend,
99
user_preferences_user_service,
1010
)
1111

1212

13-
class CouldNotCreateOrUpdateUserPreferenceError(Exception):
14-
...
13+
class CouldNotCreateOrUpdateUserPreferenceError(Exception): ...
1514

1615

1716
class BasePreferencesRepo:
@@ -20,7 +19,7 @@ class BasePreferencesRepo:
2019
@classmethod
2120
async def save(
2221
cls,
23-
conn: SAConnection,
22+
conn: AsyncConnection,
2423
*,
2524
user_id: int,
2625
product_name: str,
@@ -49,7 +48,7 @@ async def save(
4948
@classmethod
5049
async def load(
5150
cls,
52-
conn: SAConnection,
51+
conn: AsyncConnection,
5352
*,
5453
user_id: int,
5554
product_name: str,

packages/postgres-database/tests/conftest.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
user_to_groups,
3939
users,
4040
)
41+
from sqlalchemy.engine.row import Row
4142
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
4243

4344
pytest_plugins = [
@@ -324,18 +325,26 @@ async def _creator(project_uuid: uuid.UUID) -> ProjectNode:
324325

325326

326327
@pytest.fixture
327-
def create_fake_product(
328-
connection: aiopg.sa.connection.SAConnection,
329-
) -> Callable[..., Awaitable[RowProxy]]:
330-
async def _creator(product_name: str) -> RowProxy:
331-
result = await connection.execute(
332-
sa.insert(products)
333-
.values(name=product_name, host_regex=".*")
334-
.returning(sa.literal_column("*"))
335-
)
336-
assert result
337-
row = await result.first()
338-
assert row
328+
async def create_fake_product(
329+
asyncpg_engine: AsyncEngine,
330+
) -> AsyncIterator[Callable[[str], Awaitable[Row]]]:
331+
created_product_names = set()
332+
333+
async def _creator(product_name: str) -> Row:
334+
async with asyncpg_engine.begin() as connection:
335+
result = await connection.execute(
336+
sa.insert(products)
337+
.values(name=product_name, host_regex=".*")
338+
.returning(sa.literal_column("*"))
339+
)
340+
assert result
341+
row = result.one()
342+
created_product_names.add(row.name)
339343
return row
340344

341-
return _creator
345+
yield _creator
346+
347+
async with asyncpg_engine.begin() as conn:
348+
await conn.execute(
349+
products.delete().where(products.c.name.in_(created_product_names))
350+
)

packages/postgres-database/tests/test_utils_groups_extra_properties.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
GroupExtraPropertiesRepo,
2222
)
2323
from sqlalchemy import literal_column
24+
from sqlalchemy.engine.row import Row
2425
from sqlalchemy.ext.asyncio import AsyncEngine
2526

2627

@@ -84,7 +85,7 @@ async def test_get(
8485
connection: aiopg.sa.connection.SAConnection,
8586
registered_user: RowProxy,
8687
product_name: str,
87-
create_fake_product: Callable[..., Awaitable[RowProxy]],
88+
create_fake_product: Callable[[str], Awaitable[Row]],
8889
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
8990
):
9091
with pytest.raises(GroupExtraPropertiesNotFoundError):
@@ -106,7 +107,7 @@ async def test_get_v2(
106107
asyncpg_engine: AsyncEngine,
107108
registered_user: RowProxy,
108109
product_name: str,
109-
create_fake_product: Callable[..., Awaitable[RowProxy]],
110+
create_fake_product: Callable[[str], Awaitable[Row]],
110111
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
111112
):
112113
with pytest.raises(GroupExtraPropertiesNotFoundError):
@@ -157,7 +158,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
157158
connection: aiopg.sa.connection.SAConnection,
158159
product_name: str,
159160
registered_user: RowProxy,
160-
create_fake_product: Callable[..., Awaitable[RowProxy]],
161+
create_fake_product: Callable[[str], Awaitable[Row]],
161162
create_fake_group: Callable[..., Awaitable[RowProxy]],
162163
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
163164
everyone_group_id: int,
@@ -227,7 +228,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
227228
connection: aiopg.sa.connection.SAConnection,
228229
product_name: str,
229230
registered_user: RowProxy,
230-
create_fake_product: Callable[..., Awaitable[RowProxy]],
231+
create_fake_product: Callable[[str], Awaitable[Row]],
231232
create_fake_group: Callable[..., Awaitable[RowProxy]],
232233
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
233234
everyone_group_id: int,
@@ -274,7 +275,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
274275
connection: aiopg.sa.connection.SAConnection,
275276
product_name: str,
276277
registered_user: RowProxy,
277-
create_fake_product: Callable[..., Awaitable[RowProxy]],
278+
create_fake_product: Callable[[str], Awaitable[Row]],
278279
create_fake_group: Callable[..., Awaitable[RowProxy]],
279280
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
280281
everyone_group_id: int,
@@ -385,7 +386,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
385386
connection: aiopg.sa.connection.SAConnection,
386387
product_name: str,
387388
registered_user: RowProxy,
388-
create_fake_product: Callable[..., Awaitable[RowProxy]],
389+
create_fake_product: Callable[[str], Awaitable[Row]],
389390
create_fake_group: Callable[..., Awaitable[RowProxy]],
390391
create_fake_group_extra_properties: Callable[..., Awaitable[GroupExtraProperties]],
391392
everyone_group_id: int,

0 commit comments

Comments
 (0)