Skip to content

Commit

Permalink
Merge pull request #363 from specklesystems/jrm/filter-tests
Browse files Browse the repository at this point in the history
Added tests for filters
  • Loading branch information
gjedlicska authored Dec 11, 2024
2 parents 8dcc67f + 35750f1 commit d71b616
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/specklepy/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
OtherUserResource,
ProjectInviteResource,
ProjectResource,
ServerResource,
SubscriptionResource,
VersionResource,
branch,
commit,
object,
server,
stream,
subscriptions,
user,
Expand Down Expand Up @@ -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
)

Expand Down
3 changes: 1 addition & 2 deletions src/specklepy/api/resources/current/active_user_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/specklepy/api/resources/deprecated/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
42 changes: 42 additions & 0 deletions src/specklepy/core/api/inputs/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
5 changes: 0 additions & 5 deletions src/specklepy/core/api/inputs/project_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,3 @@ class ProjectUpdateRoleInput(BaseModel):
userId: str
projectId: str
role: Optional[str]


class UserProjectsFilter(BaseModel):
search: str
onlyWithRoles: Optional[Sequence[str]] = None
7 changes: 6 additions & 1 deletion src/specklepy/core/api/inputs/user_inputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Sequence

from pydantic import BaseModel

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion tests/integration/client/current/test_active_user_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
31 changes: 30 additions & 1 deletion tests/integration/client/current/test_model_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
):
Expand All @@ -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
Expand Down
43 changes: 42 additions & 1 deletion tests/integration/client/current/test_version_resource.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
):
Expand Down Expand Up @@ -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
):
Expand Down

0 comments on commit d71b616

Please sign in to comment.