-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,017 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# pylint: disable=redefined-outer-name | ||
# pylint: disable=unused-argument | ||
# pylint: disable=unused-variable | ||
# pylint: disable=too-many-arguments | ||
|
||
|
||
from enum import Enum | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, status | ||
from simcore_service_webserver._meta import API_VTAG | ||
from simcore_service_webserver.projects._trash_handlers import ( | ||
ProjectPathParams, | ||
RemoveQueryParams, | ||
) | ||
|
||
router = APIRouter( | ||
prefix=f"/{API_VTAG}", | ||
tags=["trash"], | ||
) | ||
|
||
|
||
@router.delete( | ||
"/trash", | ||
status_code=status.HTTP_204_NO_CONTENT, | ||
) | ||
def empty_trash(): | ||
... | ||
|
||
|
||
_extra_tags: list[str | Enum] = ["projects"] | ||
|
||
|
||
@router.post( | ||
"/projects/{project_id}:trash", | ||
tags=_extra_tags, | ||
status_code=status.HTTP_204_NO_CONTENT, | ||
responses={ | ||
status.HTTP_404_NOT_FOUND: {"description": "Not such a project"}, | ||
status.HTTP_409_CONFLICT: { | ||
"description": "Project is in use and cannot be trashed" | ||
}, | ||
status.HTTP_503_SERVICE_UNAVAILABLE: {"description": "Trash service error"}, | ||
}, | ||
) | ||
def trash_project( | ||
_p: Annotated[ProjectPathParams, Depends()], | ||
_q: Annotated[RemoveQueryParams, Depends()], | ||
): | ||
... | ||
|
||
|
||
@router.post( | ||
"/projects/{project_id}:untrash", | ||
tags=_extra_tags, | ||
status_code=status.HTTP_204_NO_CONTENT, | ||
) | ||
def untrash_project( | ||
_p: Annotated[ProjectPathParams, Depends()], | ||
): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
packages/models-library/src/models_library/api_schemas_webserver/folders_v2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 17 additions & 2 deletions
19
packages/models-library/src/models_library/rest_filters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
from pydantic import BaseModel | ||
from typing import Generic, TypeVar | ||
|
||
from pydantic import BaseModel, Field, Json | ||
from pydantic.generics import GenericModel | ||
|
||
|
||
class Filters(BaseModel): | ||
"""inspired by Docker API https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerList. | ||
""" | ||
Encoded as JSON. Each available filter can have its own logic (should be well documented) | ||
Inspired by Docker API https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerList. | ||
""" | ||
|
||
|
||
# Custom filter | ||
FilterT = TypeVar("FilterT", bound=Filters) | ||
|
||
|
||
class FiltersQueryParameters(GenericModel, Generic[FilterT]): | ||
filters: Json[FilterT] | None = Field( # pylint: disable=unsubscriptable-object | ||
default=None, | ||
description="Custom filter query parameter encoded as JSON", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import logging | ||
|
||
import pytest | ||
from models_library.rest_filters import Filters, FiltersQueryParameters | ||
from pydantic import Extra, ValidationError | ||
|
||
|
||
# 1. create filter model | ||
class CustomFilter(Filters): | ||
is_trashed: bool | None = None | ||
is_hidden: bool | None = None | ||
|
||
|
||
class CustomFilterStrict(CustomFilter): | ||
class Config(CustomFilter.Config): | ||
extra = Extra.forbid | ||
|
||
|
||
def test_custom_filter_query_parameters(): | ||
|
||
# 2. use generic as query parameters | ||
logging.info( | ||
"json schema is for the query \n %s", | ||
FiltersQueryParameters[CustomFilter].schema_json(indent=1), | ||
) | ||
|
||
# lets filter only is_trashed and unset is_hidden | ||
custom_filter = CustomFilter(is_trashed=True) | ||
assert custom_filter.json() == '{"is_trashed": true, "is_hidden": null}' | ||
|
||
# default to None (optional) | ||
query_param = FiltersQueryParameters[CustomFilter]() | ||
assert query_param.filters is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url_query_value,expects", | ||
[ | ||
('{"is_trashed": true, "is_hidden": null}', CustomFilter(is_trashed=True)), | ||
('{"is_trashed": true}', CustomFilter(is_trashed=True)), | ||
(None, None), | ||
], | ||
) | ||
def test_valid_filter_queries( | ||
url_query_value: str | None, expects: CustomFilter | None | ||
): | ||
query_param = FiltersQueryParameters[CustomFilter](filters=url_query_value) | ||
assert query_param.filters == expects | ||
|
||
|
||
def test_invalid_filter_query_is_ignored(): | ||
# NOTE: invalid filter get ignored! | ||
url_query_value = '{"undefined_filter": true, "is_hidden": true}' | ||
|
||
query_param = FiltersQueryParameters[CustomFilter](filters=url_query_value) | ||
assert query_param.filters == CustomFilter(is_hidden=True) | ||
|
||
|
||
@pytest.mark.xfail | ||
def test_invalid_filter_query_fails(): | ||
# NOTE: this should fail according to pydantic manual but it does not | ||
url_query_value = '{"undefined_filter": true, "is_hidden": true}' | ||
|
||
with pytest.raises(ValidationError): | ||
FiltersQueryParameters[CustomFilterStrict](filters=url_query_value) |
29 changes: 29 additions & 0 deletions
29
.../src/simcore_postgres_database/migration/versions/fce5d231e16d_new_projects_trashed_at.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""new projects trashed_at | ||
Revision ID: fce5d231e16d | ||
Revises: ea3952fe5a0e | ||
Create Date: 2024-10-23 14:32:32.350937+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "fce5d231e16d" | ||
down_revision = "ea3952fe5a0e" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"projects", sa.Column("trashed_at", sa.DateTime(timezone=True), nullable=True) | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("projects", "trashed_at") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.43.1 | ||
0.44.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.