File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -86,9 +86,10 @@ def __init__(
8686 content_permissions : Optional [str ] = None ,
8787 parent_id : Optional [str ] = None ,
8888 samples : Optional [bool ] = None ,
89+ id : Optional [str ] = None ,
8990 ) -> None :
9091 self ._content_permissions = None
91- self ._id : Optional [str ] = None
92+ self ._id : Optional [str ] = id
9293 self .description : Optional [str ] = description
9394 self .name : str = name
9495 self .content_permissions : Optional [str ] = content_permissions
Original file line number Diff line number Diff line change @@ -89,6 +89,18 @@ def delete(self, project_id: str) -> None:
8989 self .delete_request (url )
9090 logger .info (f"Deleted single project (ID: { project_id } )" )
9191
92+ @api (version = "2.0" )
93+ def get_by_id (self , project_id : str ) -> ProjectItem :
94+ """
95+ Fetch a project by ID. This is a convenience method making up for a gap in the server API.
96+ It uses the same endpoint as the update method, but without the ability to update the project.
97+ """
98+ if not project_id :
99+ error = "Project ID undefined."
100+ raise ValueError (error )
101+ project = ProjectItem (id = project_id )
102+ return self .update (project , samples = False )
103+
92104 @api (version = "2.0" )
93105 def update (self , project_item : ProjectItem , samples : bool = False ) -> ProjectItem :
94106 """
Original file line number Diff line number Diff line change @@ -79,6 +79,24 @@ def test_delete_missing_id(server: TSC.Server) -> None:
7979 with pytest .raises (ValueError ):
8080 server .projects .delete ("" )
8181
82+ def test_get_by_id (server : TSC .Server ) -> None :
83+ response_xml = UPDATE_XML .read_text ()
84+ with requests_mock .mock () as m :
85+ m .put (server .projects .baseurl + "/1d0304cd-3796-429f-b815-7258370b9b74" , text = response_xml )
86+ project = server .projects .get_by_id ("1d0304cd-3796-429f-b815-7258370b9b74" )
87+ assert "1d0304cd-3796-429f-b815-7258370b9b74" == project .id
88+ assert "Test Project" == project .name
89+ assert "Project created for testing" == project .description
90+ assert "LockedToProject" == project .content_permissions
91+ assert "9a8f2265-70f3-4494-96c5-e5949d7a1120" == project .parent_id
92+ assert "dd2239f6-ddf1-4107-981a-4cf94e415794" == project .owner_id
93+ assert "LockedToProject" == project .content_permissions
94+
95+
96+ def test_get_by_id_missing_id (server : TSC .Server ) -> None :
97+ with pytest .raises (ValueError ):
98+ server .projects .get_by_id ("" )
99+
82100
83101def test_update (server : TSC .Server ) -> None :
84102 response_xml = UPDATE_XML .read_text ()
You can’t perform that action at this time.
0 commit comments