diff --git a/src/specklepy/api/client.py b/src/specklepy/api/client.py index 5755cc5c..af6d01d4 100644 --- a/src/specklepy/api/client.py +++ b/src/specklepy/api/client.py @@ -7,12 +7,12 @@ OtherUserResource, ProjectInviteResource, ProjectResource, + ServerResource, SubscriptionResource, VersionResource, branch, commit, object, - server, stream, subscriptions, user, @@ -69,7 +69,7 @@ def __init__( self.account = Account() def _init_resources(self) -> None: - self.server = server.Resource( + self.server = ServerResource( account=self.account, basepath=self.url, client=self.httpclient ) diff --git a/src/specklepy/api/resources/current/active_user_resource.py b/src/specklepy/api/resources/current/active_user_resource.py index b8f4c14e..ed16eb0d 100644 --- a/src/specklepy/api/resources/current/active_user_resource.py +++ b/src/specklepy/api/resources/current/active_user_resource.py @@ -3,8 +3,7 @@ from deprecated import deprecated -from specklepy.core.api.inputs.project_inputs import UserProjectsFilter -from specklepy.core.api.inputs.user_inputs import UserUpdateInput +from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput from specklepy.core.api.models import ( PendingStreamCollaborator, Project, diff --git a/src/specklepy/api/resources/deprecated/server.py b/src/specklepy/api/resources/deprecated/server.py index f44203c5..7ddb805e 100644 --- a/src/specklepy/api/resources/deprecated/server.py +++ b/src/specklepy/api/resources/deprecated/server.py @@ -4,6 +4,6 @@ from specklepy.core.api.models.deprecated import FE1_DEPRECATION_VERSION -@deprecated(reason="Renamed to ActiveUserResource", version=FE1_DEPRECATION_VERSION) +@deprecated(reason="Renamed to ServerResource", version=FE1_DEPRECATION_VERSION) class Resource(ServerResource): """Renamed to ServerResource""" diff --git a/src/specklepy/core/api/inputs/__init__.py b/src/specklepy/core/api/inputs/__init__.py new file mode 100644 index 00000000..1cf5ab87 --- /dev/null +++ b/src/specklepy/core/api/inputs/__init__.py @@ -0,0 +1,42 @@ +from specklepy.core.api.inputs.model_inputs import ( + CreateModelInput, + DeleteModelInput, + ModelVersionsFilter, + UpdateModelInput, +) +from specklepy.core.api.inputs.project_inputs import ( + ProjectCreateInput, + ProjectInviteCreateInput, + ProjectInviteUseInput, + ProjectModelsFilter, + ProjectUpdateInput, + ProjectUpdateRoleInput, +) +from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput +from specklepy.core.api.inputs.version_inputs import ( + CreateVersionInput, + DeleteVersionsInput, + MarkReceivedVersionInput, + MoveVersionsInput, + UpdateVersionInput, +) + +__all__ = [ + "CreateModelInput", + "DeleteModelInput", + "UpdateModelInput", + "ModelVersionsFilter", + "ProjectCreateInput", + "ProjectInviteCreateInput", + "ProjectInviteUseInput", + "ProjectModelsFilter", + "ProjectUpdateInput", + "ProjectUpdateRoleInput", + "UserProjectsFilter", + "UserUpdateInput", + "UpdateVersionInput", + "MoveVersionsInput", + "DeleteVersionsInput", + "CreateVersionInput", + "MarkReceivedVersionInput", +] diff --git a/src/specklepy/core/api/inputs/project_inputs.py b/src/specklepy/core/api/inputs/project_inputs.py index 69242a93..89f46deb 100644 --- a/src/specklepy/core/api/inputs/project_inputs.py +++ b/src/specklepy/core/api/inputs/project_inputs.py @@ -45,8 +45,3 @@ class ProjectUpdateRoleInput(BaseModel): userId: str projectId: str role: Optional[str] - - -class UserProjectsFilter(BaseModel): - search: str - onlyWithRoles: Optional[Sequence[str]] = None diff --git a/src/specklepy/core/api/inputs/user_inputs.py b/src/specklepy/core/api/inputs/user_inputs.py index 18b1efea..27898444 100644 --- a/src/specklepy/core/api/inputs/user_inputs.py +++ b/src/specklepy/core/api/inputs/user_inputs.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Optional, Sequence from pydantic import BaseModel @@ -8,3 +8,8 @@ class UserUpdateInput(BaseModel): bio: Optional[str] = None company: Optional[str] = None name: Optional[str] = None + + +class UserProjectsFilter(BaseModel): + search: str + onlyWithRoles: Optional[Sequence[str]] = None diff --git a/src/specklepy/core/api/resources/current/active_user_resource.py b/src/specklepy/core/api/resources/current/active_user_resource.py index 35d3bbf9..e7ce1e8f 100644 --- a/src/specklepy/core/api/resources/current/active_user_resource.py +++ b/src/specklepy/core/api/resources/current/active_user_resource.py @@ -4,8 +4,7 @@ from deprecated import deprecated from gql import gql -from specklepy.core.api.inputs.project_inputs import UserProjectsFilter -from specklepy.core.api.inputs.user_inputs import UserUpdateInput +from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput from specklepy.core.api.models import ( ActivityCollection, PendingStreamCollaborator, diff --git a/tests/integration/client/current/test_active_user_resource.py b/tests/integration/client/current/test_active_user_resource.py index fd5a7bbf..a35f340d 100644 --- a/tests/integration/client/current/test_active_user_resource.py +++ b/tests/integration/client/current/test_active_user_resource.py @@ -2,7 +2,7 @@ from specklepy.api.client import SpeckleClient from specklepy.core.api.inputs.project_inputs import ProjectCreateInput -from specklepy.core.api.inputs.user_inputs import UserUpdateInput +from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput from specklepy.core.api.models import ResourceCollection, User @@ -42,3 +42,21 @@ def test_active_user_get_projects(self, client: SpeckleClient): assert len(res.items) == len(existing.items) + 2 assert any(project.id == p1.id for project in res.items) assert any(project.id == p2.id for project in res.items) + + def test_active_user_get_projects_with_filter(self, client: SpeckleClient): + # Since the client may be reused for other tests, + # this test does rely on no other test creating a project with "Search for me" in its name + p1 = client.project.create( + ProjectCreateInput(name="Search for me!", description=None, visibility=None) + ) + _ = client.project.create( + ProjectCreateInput(name="But not me!", description=None, visibility=None) + ) + filter = UserProjectsFilter(search="Search for me") + + res = client.active_user.get_projects(filter=filter) + + assert isinstance(res, ResourceCollection) + assert len(res.items) == 1 + assert res.totalCount == 1 + assert res.items[0].id == p1.id diff --git a/tests/integration/client/current/test_model_resource.py b/tests/integration/client/current/test_model_resource.py index 34a4520b..0c3f0aee 100644 --- a/tests/integration/client/current/test_model_resource.py +++ b/tests/integration/client/current/test_model_resource.py @@ -6,7 +6,10 @@ DeleteModelInput, UpdateModelInput, ) -from specklepy.core.api.inputs.project_inputs import ProjectCreateInput +from specklepy.core.api.inputs.project_inputs import ( + ProjectCreateInput, + ProjectModelsFilter, +) from specklepy.core.api.models.current import ( Model, Project, @@ -65,6 +68,18 @@ def test_model_get( assert result.createdAt == test_model.createdAt assert result.updatedAt == test_model.updatedAt + def test_models_get_with_filter( + self, client: SpeckleClient, test_model: Model, test_project: Project + ): + filter = ProjectModelsFilter(search=test_model.name) + + result = client.model.get_models(test_project.id, models_filter=filter) + + assert isinstance(result, ResourceCollection) + assert len(result.items) == 1 + assert result.totalCount == 1 + assert result.items[0].id == test_model.id + def test_get_models( self, client: SpeckleClient, test_project: Project, test_model: Model ): @@ -82,6 +97,20 @@ def test_project_get_models( assert isinstance(result, ProjectWithModels) assert result.id == test_project.id + assert isinstance(result.models, ResourceCollection) + assert len(result.models.items) == 1 + assert result.models.totalCount == 1 + assert result.models.items[0].id == test_model.id + + def test_project_get_models_with_filter( + self, client: SpeckleClient, test_project: Project, test_model: Model + ): + filter = ProjectModelsFilter(search=test_model.name) + result = client.project.get_with_models(test_project.id, models_filter=filter) + + assert isinstance(result, ProjectWithModels) + assert result.id == test_project.id + assert isinstance(result.models, ResourceCollection) assert len(result.models.items) == 1 assert result.models.totalCount == 1 assert result.models.items[0].id == test_model.id diff --git a/tests/integration/client/current/test_version_resource.py b/tests/integration/client/current/test_version_resource.py index afa7633b..498808f7 100644 --- a/tests/integration/client/current/test_version_resource.py +++ b/tests/integration/client/current/test_version_resource.py @@ -1,7 +1,7 @@ import pytest from specklepy.api.client import SpeckleClient -from specklepy.core.api.inputs.model_inputs import CreateModelInput +from specklepy.core.api.inputs.model_inputs import CreateModelInput, ModelVersionsFilter from specklepy.core.api.inputs.project_inputs import ProjectCreateInput from specklepy.core.api.inputs.version_inputs import ( DeleteVersionsInput, @@ -76,6 +76,26 @@ def test_versions_get( assert result.totalCount == 1 assert result.items[0].id == test_version.id + def test_versions_get_with_filter( + self, + client: SpeckleClient, + test_model_1: Model, + test_project: Project, + test_version: Version, + ): + filter = ModelVersionsFilter( + priorityIds=[test_version.id], priorityIdsOnly=True + ) + + result = client.version.get_versions( + test_model_1.id, test_project.id, filter=filter + ) + + assert isinstance(result, ResourceCollection) + assert len(result.items) == 1 + assert result.totalCount == 1 + assert result.items[0].id == test_version.id + def test_version_received( self, client: SpeckleClient, test_version: Version, test_project: Project ): @@ -103,6 +123,27 @@ def test_model_get_with_versions( assert result.versions.totalCount == 1 assert result.versions.items[0].id == test_version.id + def test_model_get_with_versions_with_filter( + self, + client: SpeckleClient, + test_model_1: Model, + test_project: Project, + test_version: Version, + ): + filter = ModelVersionsFilter( + priorityIds=[test_version.id], priorityIdsOnly=True + ) + + result = client.model.get_with_versions( + test_model_1.id, test_project.id, versions_filter=filter + ) + + assert isinstance(result, ModelWithVersions) + assert len(result.versions.items) == 1 + assert result.versions.totalCount == 1 + assert isinstance(result.versions, ResourceCollection) + assert result.versions.items[0].id == test_version.id + def test_version_update( self, client: SpeckleClient, test_version: Version, test_project: Project ):