Skip to content

Commit 06ca4d6

Browse files
committed
Extend content.get() to support includes param
1 parent b61e2db commit 06ca4d6

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

integration/tests/posit/connect/test_content.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ def test_count(self):
2525
def test_get(self):
2626
assert self.client.content.get(self.content["guid"]) == self.content
2727

28+
def test_get_with_include_string(self):
29+
assert self.client.content.get(self.content["guid"], include="owner")
30+
31+
def test_get_with_include_list(self):
32+
assert self.client.content.get(
33+
self.content["guid"], include=["owner", "tags", "vanity_url"]
34+
)
35+
2836
def test_find(self):
2937
assert self.client.content.find()
3038

src/posit/connect/content.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,16 +983,34 @@ def find_one(self, **conditions) -> Optional[ContentItem]:
983983
items = self.find(**conditions)
984984
return next(iter(items), None)
985985

986-
def get(self, guid: str) -> ContentItem:
986+
def get(
987+
self,
988+
guid: str,
989+
*,
990+
include: Optional[
991+
Literal["owner", "tags", "vanity_url"] | list[Literal["owner", "tags", "vanity_url"]]
992+
] = None,
993+
) -> ContentItem:
987994
"""Get a content item.
988995
989996
Parameters
990997
----------
991998
guid : str
999+
The unique identifier of the content item.
1000+
include : str or list of str, optional
1001+
Additional details to include in the response.
1002+
Allowed values: 'owner', 'tags', 'vanity_url'.
9921003
9931004
Returns
9941005
-------
9951006
ContentItem
9961007
"""
997-
response = self._ctx.client.get(f"v1/content/{guid}")
1008+
params = {}
1009+
if include is not None:
1010+
if isinstance(include, list):
1011+
params["include"] = ",".join(include)
1012+
else:
1013+
params["include"] = include
1014+
1015+
response = self._ctx.client.get(f"v1/content/{guid}", params=params)
9981016
return ContentItem(self._ctx, **response.json())

tests/posit/connect/test_content.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test(self):
169169
assert content[2]["name"] == "My-Streamlit-app"
170170

171171
@responses.activate
172-
def test_params_include(self):
172+
def test_params_include_string(self):
173173
# behavior
174174
mock_get = responses.get(
175175
"https://connect.example/__api__/v1/content",
@@ -204,24 +204,6 @@ def test_params_include_list(self):
204204
# assert
205205
assert mock_get.call_count == 1
206206

207-
@responses.activate
208-
def test_params_include_none(self):
209-
# behavior
210-
mock_get = responses.get(
211-
"https://connect.example/__api__/v1/content",
212-
json=load_mock("v1/content.json"),
213-
match=[matchers.query_param_matcher({})],
214-
)
215-
216-
# setup
217-
client = Client("https://connect.example", "12345")
218-
219-
# invoke
220-
client.content.find(include=None)
221-
222-
# assert
223-
assert mock_get.call_count == 1
224-
225207

226208
class TestContentsFindBy:
227209
@responses.activate
@@ -373,6 +355,38 @@ def test(self):
373355
get_one = con.content.get("f2f37341-e21d-3d80-c698-a935ad614066")
374356
assert get_one["name"] == "Performance-Data-1671216053560"
375357

358+
@responses.activate
359+
def test_get_with_include_string(self):
360+
guid = "f2f37341-e21d-3d80-c698-a935ad614066"
361+
mock_get = responses.get(
362+
f"https://connect.example/__api__/v1/content/{guid}",
363+
json=load_mock(f"v1/content/{guid}.json"),
364+
match=[matchers.query_param_matcher({"include": "owner"})],
365+
)
366+
367+
con = Client("https://connect.example", "12345")
368+
content = con.content.get(guid, include="owner")
369+
assert content["guid"] == guid
370+
371+
# assert
372+
assert mock_get.call_count == 1
373+
374+
375+
@responses.activate
376+
def test_get_with_include_list(self):
377+
guid = "f2f37341-e21d-3d80-c698-a935ad614066"
378+
mock_get = responses.get(
379+
f"https://connect.example/__api__/v1/content/{guid}",
380+
json=load_mock(f"v1/content/{guid}.json"),
381+
match=[matchers.query_param_matcher({"include": "owner,tags,vanity_url"})],
382+
)
383+
384+
con = Client("https://connect.example", "12345")
385+
content = con.content.get(guid, include=["owner", "tags", "vanity_url"])
386+
assert content["guid"] == guid
387+
388+
# assert
389+
assert mock_get.call_count == 1
376390

377391
class TestContentsCount:
378392
@responses.activate

0 commit comments

Comments
 (0)