Skip to content

Commit

Permalink
fix type signature of include
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Sep 13, 2024
1 parent 58f457e commit b018dd9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b018dd9

Please sign in to comment.