Skip to content

Commit d04650d

Browse files
authored
Merge pull request #759 from CitrineInformatics/PLA-9734/list-projects-v3
make citrine.projects.list() v3 backward compatible with v1
2 parents c243b3a + ae0f24d commit d04650d

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

docs/source/FAQ/team_management_migration.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Previously:
4343
4444
project = citrine.projects.get(project_id)
4545
# or
46+
projects = citrine.projects.list()
47+
# or
4648
project = citrine.projects.register(name="My Project")
4749
# or
4850
project = find_or_create_project(
@@ -64,6 +66,8 @@ The ``Team`` equivalent:
6466
6567
# Then find your project within the team
6668
project = team.projects.get("baaa467e-1758-43a8-97c7-76e569d0dcab")
69+
# or
70+
projects = team.projects.list()
6771
# or
6872
project = team.projects.register(name="My Project")
6973
# or
@@ -72,6 +76,17 @@ The ``Team`` equivalent:
7276
project_name="My Project"
7377
)
7478
79+
You should modify your code to make use of these new access patterns, but for backward
80+
compatibility purposes, the following methods will continue to work after the teams
81+
migration:
82+
83+
.. code-block:: python
84+
85+
project = citrine.projects.get(project_id)
86+
87+
projects = citrine.projects.list()
88+
89+
7590
If your scripts managed user membership in projects, that user management now works on the team
7691
level instead.
7792

src/citrine/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.31.2'
1+
__version__ = '1.32.0'

src/citrine/resources/project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,9 @@ def list(self, *,
721721

722722
def _list_v3(self, *, page: Optional[int] = None, per_page: int = 1000) -> Iterator[Project]:
723723
if self.team_id is None:
724-
raise NotImplementedError("Please use team.projects")
725-
726-
path = format_escaped_url('/teams/{team_id}/projects', team_id=self.team_id)
724+
path = '/projects'
725+
else:
726+
path = format_escaped_url('/teams/{team_id}/projects', team_id=self.team_id)
727727

728728
fetcher = partial(self._fetch_page, path=path)
729729
return self._paginator.paginate(page_fetcher=fetcher,

tests/resources/test_project.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,17 @@ def test_list_projects_v3(collection_v3, session_v3):
601601
assert 5 == len(projects)
602602

603603

604-
def test_failed_list_v3_no_team(session_v3):
604+
def test_list_v3_no_team(session_v3):
605605
project_collection = ProjectCollection(session=session_v3)
606-
with pytest.raises(NotImplementedError):
607-
project_collection.list()
606+
projects_data = ProjectDataFactory.create_batch(5)
607+
session_v3.set_response({'projects': projects_data})
608+
609+
projects = list(project_collection.list())
610+
611+
assert 1 == session_v3.num_calls
612+
expected_call = FakeCall(method='GET', path=f'/projects', params={'per_page': 1000})
613+
assert expected_call == session_v3.last_call
614+
assert 5 == len(projects)
608615

609616

610617
def test_list_projects_filters_non_projects(collection, session):

0 commit comments

Comments
 (0)