diff --git a/src/posit/connect/content.py b/src/posit/connect/content.py index 36608396..50ed3ae3 100644 --- a/src/posit/connect/content.py +++ b/src/posit/connect/content.py @@ -430,7 +430,10 @@ def find( *, name: Optional[str] = None, owner_guid: Optional[str] = None, - include: str | list[Literal["owner", "tags", "vanity_url"]] = [], + include: Optional[ + Literal["owner", "tags", "vanity_url"] + | list[Literal["owner", "tags", "vanity_url"]] + ] = None, ) -> List[ContentItem]: """Find content matching the specified criteria. @@ -462,7 +465,9 @@ def find( *, name: Optional[str] = None, owner_guid: Optional[str] = None, - include: str | list[Literal["owner", "tags"]] = [], + include: Optional[ + Literal["owner", "tags"] | list[Literal["owner", "tags"]] + ] = None, ) -> List[ContentItem]: """Find content matching the specified criteria. @@ -489,20 +494,31 @@ def find( ... @overload - def find(self, **conditions) -> List[ContentItem]: ... + def find( + self, include: Optional[str | list[Any]], **conditions + ) -> List[ContentItem]: ... - def find(self, **conditions) -> List[ContentItem]: + def find( + self, include: Optional[str | list[Any]] = None, **conditions + ) -> List[ContentItem]: """Find content matching the specified conditions. Returns ------- List[ContentItem] """ + if isinstance(include, list): + include = ",".join(include) + + if include is not None: + conditions["include"] = include + + if self.owner_guid: + conditions["owner_guid"] = self.owner_guid + path = "v1/content" url = self.params.url + path - response = self.params.session.get( - url, params={"owner_guid": self.owner_guid, **conditions} - ) + response = self.params.session.get(url, params=conditions) return [ ContentItem( self.params, @@ -517,7 +533,10 @@ def find_one( *, name: Optional[str] = None, owner_guid: Optional[str] = None, - include: str | list[Literal["owner", "tags", "vanity_url"]] = [], + include: Optional[ + Literal["owner", "tags", "vanity_url"] + | list[Literal["owner", "tags", "vanity_url"]] + ] = None, ) -> Optional[ContentItem]: """Find first content result matching the specified conditions. @@ -547,7 +566,9 @@ def find_one( *, name: Optional[str] = None, owner_guid: Optional[str] = None, - include: str | list[Literal["owner", "tags"]] = [], + include: Optional[ + Literal["owner", "tags"] | list[Literal["owner", "tags"]] + ] = None, ) -> Optional[ContentItem]: """Find first content result matching the specified conditions. diff --git a/tests/posit/connect/test_content.py b/tests/posit/connect/test_content.py index b42a3f27..87e7bfbd 100644 --- a/tests/posit/connect/test_content.py +++ b/tests/posit/connect/test_content.py @@ -368,6 +368,24 @@ def test_params_include(self): # assert assert mock_get.call_count == 1 + @responses.activate + def test_params_include_list(self): + # behavior + mock_get = responses.get( + "https://connect.example/__api__/v1/content", + json=load_mock("v1/content.json"), + match=[matchers.query_param_matcher({"include": "tags,owner"})], + ) + + # setup + client = Client("https://connect.example", "12345") + + # invoke + client.content.find(include=["tags", "owner"]) + + # assert + assert mock_get.call_count == 1 + @responses.activate def test_params_include_none(self): # behavior