Skip to content

Commit 603dcdd

Browse files
authored
Merge pull request #1000 from CitrineInformatics/feature/pne-7426-expose-project-archive-status
[PNE-7426] Expose Project.archived.
2 parents 084e295 + 2764ac1 commit 603dcdd

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

src/citrine/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.24.1"
1+
__version__ = "3.25.0"

src/citrine/resources/project.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Resources that represent both individual and collections of projects."""
22
from deprecation import deprecated
3+
from functools import partial
34
from typing import Optional, Dict, List, Union, Iterable, Tuple, Iterator
45
from uuid import UUID
56
from warnings import warn
@@ -77,6 +78,8 @@ class Project(Resource['Project']):
7778
"""str: Status of the project."""
7879
created_at = properties.Optional(properties.Datetime(), 'created_at')
7980
"""int: Time the project was created, in seconds since epoch."""
81+
archived = properties.Optional(properties.Boolean, 'archived')
82+
"""bool: Whether the project is archived."""
8083
_team_id = properties.Optional(properties.UUID, "team.id", serializable=False)
8184

8285
def __init__(self,
@@ -599,9 +602,57 @@ def register(self, name: str, *, description: Optional[str] = None) -> Project:
599602
project = Project(name, description=description)
600603
return super().register(project)
601604

605+
def _list_base(self, *, per_page: int = 1000, archived: Optional[bool] = None):
606+
filters = {}
607+
if archived is not None:
608+
filters["archived"] = str(archived).lower()
609+
610+
fetcher = partial(self._fetch_page, additional_params=filters, version=self._api_version)
611+
return self._paginator.paginate(page_fetcher=fetcher,
612+
collection_builder=self._build_collection_elements,
613+
per_page=per_page)
614+
602615
def list(self, *, per_page: int = 1000) -> Iterator[Project]:
603616
"""
604-
List projects using pagination.
617+
List all projects using pagination.
618+
619+
Parameters
620+
---------
621+
per_page: int, optional
622+
Max number of results to return per page. Default is 1000. This parameter
623+
is used when making requests to the backend service. If the page parameter
624+
is specified it limits the maximum number of elements in the response.
625+
626+
Returns
627+
-------
628+
Iterator[Project]
629+
Projects in this collection.
630+
631+
"""
632+
return self._list_base(per_page=per_page)
633+
634+
def list_active(self, *, per_page: int = 1000) -> Iterator[Project]:
635+
"""
636+
List non-archived projects using pagination.
637+
638+
Parameters
639+
---------
640+
per_page: int, optional
641+
Max number of results to return per page. Default is 1000. This parameter
642+
is used when making requests to the backend service. If the page parameter
643+
is specified it limits the maximum number of elements in the response.
644+
645+
Returns
646+
-------
647+
Iterator[Project]
648+
Projects in this collection.
649+
650+
"""
651+
return self._list_base(per_page=per_page, archived=False)
652+
653+
def list_archived(self, *, per_page: int = 1000) -> Iterable[Project]:
654+
"""
655+
List archived projects using pagination.
605656
606657
Parameters
607658
---------
@@ -616,7 +667,7 @@ def list(self, *, per_page: int = 1000) -> Iterator[Project]:
616667
Projects in this collection.
617668
618669
"""
619-
return super().list(per_page=per_page)
670+
return self._list_base(per_page=per_page, archived=True)
620671

621672
def search_all(self, search_params: Optional[Dict]) -> Iterable[Dict]:
622673
"""

tests/resources/test_project.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,46 @@ def test_list_projects(collection, session):
418418

419419
# Then
420420
assert 1 == session.num_calls
421-
expected_call = FakeCall(method='GET', path=f'/teams/{collection.team_id}/projects', params={'per_page': 1000, 'page': 1})
421+
expected_call = FakeCall(method='GET',
422+
path=f'/teams/{collection.team_id}/projects',
423+
params={'per_page': 1000, 'page': 1},
424+
version="v3")
425+
assert expected_call == session.last_call
426+
assert 5 == len(projects)
427+
428+
429+
def test_list_archived_projects(collection, session):
430+
# Given
431+
projects_data = ProjectDataFactory.create_batch(5)
432+
session.set_response({'projects': projects_data})
433+
434+
# When
435+
projects = list(collection.list_archived())
436+
437+
# Then
438+
assert 1 == session.num_calls
439+
expected_call = FakeCall(method='GET',
440+
path=f'/teams/{collection.team_id}/projects',
441+
params={'per_page': 1000, 'page': 1, 'archived': "true"},
442+
version="v3")
443+
assert expected_call == session.last_call
444+
assert 5 == len(projects)
445+
446+
447+
def test_list_active_projects(collection, session):
448+
# Given
449+
projects_data = ProjectDataFactory.create_batch(5)
450+
session.set_response({'projects': projects_data})
451+
452+
# When
453+
projects = list(collection.list_active())
454+
455+
# Then
456+
assert 1 == session.num_calls
457+
expected_call = FakeCall(method='GET',
458+
path=f'/teams/{collection.team_id}/projects',
459+
params={'per_page': 1000, 'page': 1, 'archived': "false"},
460+
version="v3")
422461
assert expected_call == session.last_call
423462
assert 5 == len(projects)
424463

0 commit comments

Comments
 (0)