Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/models-library/src/models_library/functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from collections.abc import Mapping
from enum import Enum
from typing import Annotated, Any, Literal, TypeAlias
Expand Down Expand Up @@ -93,6 +94,7 @@ class FunctionBase(BaseModel):

class RegisteredFunctionBase(FunctionBase):
uid: FunctionID
created_at: datetime.datetime


class ProjectFunction(FunctionBase):
Expand Down Expand Up @@ -149,6 +151,7 @@ class FunctionJobBase(BaseModel):

class RegisteredFunctionJobBase(FunctionJobBase):
uid: FunctionJobID
created_at: datetime.datetime


class ProjectFunctionJob(FunctionJobBase):
Expand Down Expand Up @@ -204,6 +207,7 @@ class FunctionJobCollection(BaseModel):

class RegisteredFunctionJobCollection(FunctionJobCollection):
uid: FunctionJobCollectionID
created_at: datetime.datetime


class FunctionJobCollectionStatus(BaseModel):
Expand All @@ -222,6 +226,7 @@ class FunctionJobDB(BaseModel):

class RegisteredFunctionJobDB(FunctionJobDB):
uuid: FunctionJobID
created: datetime.datetime


class FunctionDB(BaseModel):
Expand All @@ -236,6 +241,7 @@ class FunctionDB(BaseModel):

class RegisteredFunctionDB(FunctionDB):
uuid: FunctionID
created: datetime.datetime


class FunctionJobCollectionDB(BaseModel):
Expand All @@ -245,6 +251,7 @@ class FunctionJobCollectionDB(BaseModel):

class RegisteredFunctionJobCollectionDB(FunctionJobCollectionDB):
uuid: FunctionJobCollectionID
created: datetime.datetime


class FunctionIDString(ConstrainedStr):
Expand Down
46 changes: 44 additions & 2 deletions services/api-server/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10093,11 +10093,17 @@
"type": "string",
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
}
},
"type": "object",
"required": [
"uid"
"uid",
"created_at"
],
"title": "RegisteredFunctionJobCollection"
},
Expand Down Expand Up @@ -10163,6 +10169,11 @@
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"project_id": {
"type": "string",
"format": "uuid",
Expand All @@ -10175,6 +10186,7 @@
"output_schema",
"default_inputs",
"uid",
"created_at",
"project_id"
],
"title": "RegisteredProjectFunction"
Expand Down Expand Up @@ -10229,6 +10241,11 @@
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"project_job_id": {
"type": "string",
"format": "uuid",
Expand All @@ -10241,6 +10258,7 @@
"inputs",
"outputs",
"uid",
"created_at",
"project_job_id"
],
"title": "RegisteredProjectFunctionJob"
Expand Down Expand Up @@ -10307,6 +10325,11 @@
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"code_url": {
"type": "string",
"title": "Code Url"
Expand All @@ -10318,6 +10341,7 @@
"output_schema",
"default_inputs",
"uid",
"created_at",
"code_url"
],
"title": "RegisteredPythonCodeFunction"
Expand Down Expand Up @@ -10371,14 +10395,20 @@
"type": "string",
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
}
},
"type": "object",
"required": [
"function_uid",
"inputs",
"outputs",
"uid"
"uid",
"created_at"
],
"title": "RegisteredPythonCodeFunctionJob"
},
Expand Down Expand Up @@ -10444,6 +10474,11 @@
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"solver_key": {
"type": "string",
"pattern": "^simcore/services/((comp|dynamic|frontend))/([a-z0-9][a-z0-9_.-]*/)*([a-z0-9-_]+[a-z0-9])$",
Expand All @@ -10461,6 +10496,7 @@
"output_schema",
"default_inputs",
"uid",
"created_at",
"solver_key",
"solver_version"
],
Expand Down Expand Up @@ -10516,6 +10552,11 @@
"format": "uuid",
"title": "Uid"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"solver_job_id": {
"type": "string",
"format": "uuid",
Expand All @@ -10528,6 +10569,7 @@
"inputs",
"outputs",
"uid",
"created_at",
"solver_job_id"
],
"title": "RegisteredSolverFunctionJob"
Expand Down
21 changes: 18 additions & 3 deletions services/api-server/tests/unit/api_functions/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# pylint: disable=no-self-use
# pylint: disable=cyclic-import

import datetime
from collections.abc import Callable
from typing import Any
from uuid import uuid4
Expand Down Expand Up @@ -119,7 +120,13 @@ def mock_function(

@pytest.fixture
def mock_registered_function(mock_function: Function) -> RegisteredFunction:
return RegisteredProjectFunction(**{**mock_function.dict(), "uid": str(uuid4())})
return RegisteredProjectFunction(
**{
**mock_function.dict(),
"uid": str(uuid4()),
"created_at": datetime.datetime.now(datetime.UTC),
}
)


@pytest.fixture
Expand All @@ -141,7 +148,11 @@ def mock_registered_function_job(
mock_function_job: FunctionJob,
) -> RegisteredFunctionJob:
return RegisteredProjectFunctionJob(
**{**mock_function_job.dict(), "uid": str(uuid4())}
**{
**mock_function_job.dict(),
"uid": str(uuid4()),
"created_at": datetime.datetime.now(datetime.UTC),
}
)


Expand All @@ -165,7 +176,11 @@ def mock_registered_function_job_collection(
mock_function_job_collection: FunctionJobCollection,
) -> RegisteredFunctionJobCollection:
return RegisteredFunctionJobCollection(
**{**mock_function_job_collection.model_dump(), "uid": str(uuid4())}
**{
**mock_function_job_collection.model_dump(),
"uid": str(uuid4()),
"created_at": datetime.datetime.now(datetime.UTC),
}
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=unused-argument
# pylint: disable=redefined-outer-name

import datetime
from collections.abc import Callable
from typing import Any
from uuid import uuid4
Expand All @@ -27,20 +28,19 @@ async def test_register_function(
mock_handler_in_functions_rpc_interface: Callable[[str, Any], None],
mock_function: ProjectFunction,
auth: httpx.BasicAuth,
mock_registered_function: RegisteredProjectFunction,
) -> None:
registered_function = RegisteredProjectFunction(
**{**mock_function.model_dump(), "uid": str(uuid4())}
mock_handler_in_functions_rpc_interface(
"register_function", mock_registered_function
)

mock_handler_in_functions_rpc_interface("register_function", registered_function)
response = await client.post(
f"{API_VTAG}/functions", json=mock_function.model_dump(mode="json"), auth=auth
)
assert response.status_code == status.HTTP_200_OK
data = response.json()
returned_function = RegisteredProjectFunction.model_validate(data)
assert returned_function.uid is not None
assert returned_function == registered_function
assert returned_function == mock_registered_function


async def test_register_function_invalid(
Expand Down Expand Up @@ -391,6 +391,7 @@ async def test_register_function_job_collection(
{
**mock_function_job_collection.model_dump(),
"uid": str(uuid4()),
"created_at": datetime.datetime.now(datetime.UTC),
}
)
)
Expand Down Expand Up @@ -425,6 +426,7 @@ async def test_get_function_job_collection(
"title": "Test Collection",
"description": "A test function job collection",
"job_ids": [str(uuid4()), str(uuid4())],
"created_at": datetime.datetime.now(datetime.UTC),
}
)
)
Expand Down Expand Up @@ -456,6 +458,7 @@ async def test_list_function_job_collections(
"title": "Test Collection",
"description": "A test function job collection",
"job_ids": [str(uuid4()), str(uuid4())],
"created_at": datetime.datetime.now(datetime.UTC),
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15462,6 +15462,10 @@ components:
type: string
format: uuid
title: Uid
createdAt:
type: string
format: date-time
title: Createdat
projectId:
type: string
format: uuid
Expand All @@ -15472,6 +15476,7 @@ components:
- outputSchema
- defaultInputs
- uid
- createdAt
- projectId
title: RegisteredProjectFunctionGet
RegisteredSolverFunctionGet:
Expand Down Expand Up @@ -15514,6 +15519,10 @@ components:
type: string
format: uuid
title: Uid
createdAt:
type: string
format: date-time
title: Createdat
solverKey:
type: string
pattern: ^simcore/services/((comp|dynamic|frontend))/([a-z0-9][a-z0-9_.-]*/)*([a-z0-9-_]+[a-z0-9])$
Expand All @@ -15528,6 +15537,7 @@ components:
- outputSchema
- defaultInputs
- uid
- createdAt
- solverKey
- solverVersion
title: RegisteredSolverFunctionGet
Expand Down
Loading
Loading