-
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
4 changed files
with
93 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Sequence, overload | ||
|
||
from cognite.client._api_client import APIClient | ||
from cognite.client.data_classes import Project, ProjectUpdate, ProjectWrite | ||
from cognite.client.data_classes import Project, ProjectList, ProjectUpdate, ProjectURLNameList, ProjectWrite | ||
|
||
|
||
class ProjectsAPI(APIClient): | ||
_RESOURCE_PATH = "/projects" | ||
|
||
@overload | ||
def create(self, item: ProjectWrite) -> Project: | ||
... | ||
|
||
@overload | ||
def create(self, item: Sequence[ProjectWrite]) -> ProjectList: | ||
... | ||
|
||
def create(self, item: ProjectWrite | Sequence[ProjectWrite]) -> Project | ProjectList: | ||
"""`Create a project <https://developer.cognite.com/api#tag/Projects/operation/createProject>`_""" | ||
raise NotImplementedError | ||
return self._create_multiple(item, list_cls=ProjectList, resource_cls=Project, input_resource_cls=ProjectWrite) | ||
|
||
def retrieve(self, project: str) -> Project: | ||
"""`Retrieve a project <https://developer.cognite.com/api#tag/Projects/operation/getProject>`_""" | ||
raise NotImplementedError | ||
item = self._get(f"{self._RESOURCE_PATH}/{project}") | ||
return Project._load(item.json(), cognite_client=self._cognite_client) | ||
|
||
def update(self, item: ProjectWrite | ProjectUpdate) -> Project: | ||
"""`Update a project <https://developer.cognite.com/api#tag/Projects/operation/updateProject>`_""" | ||
raise NotImplementedError | ||
return self._update_multiple(item, list_cls=ProjectList, resource_cls=Project, update_cls=ProjectUpdate) | ||
|
||
def list(self) -> list[str]: | ||
def list(self) -> ProjectURLNameList: | ||
"""`List all projects <https://developer.cognite.com/api#tag/Projects/operation/listProjects>`_""" | ||
raise NotImplementedError | ||
items = self._get(self._RESOURCE_PATH) | ||
return ProjectURLNameList.load(items.json(), cognite_client=self._cognite_client) |
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,20 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from cognite.client.data_classes import ProjectURLName, ProjectURLNameList | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def available_projects(cognite_client) -> ProjectURLNameList: | ||
if projects := cognite_client.iam.projects.list(): | ||
return projects | ||
pytest.skip("Can't test projects without any projects available", allow_module_level=True) | ||
|
||
|
||
@pytest.mark.skip(reason="Lack access to projects to perform operations") | ||
class TestProjects: | ||
def test_list_projects(self, available_projects: ProjectURLNameList) -> None: | ||
assert len(available_projects) >= 1, "Expected at least one project" | ||
assert isinstance(available_projects, ProjectURLNameList) | ||
assert isinstance(available_projects[0], ProjectURLName) |