Skip to content

Commit 7a10e0d

Browse files
authored
feat: extend content.get() to automatically use include param (#420)
Adds `include` param support for `content.get()` - Add the param support, opting to hardcode it so it is always used - Add unit test - Add integration test - Also manually verified by testing locally against a live Connect instance Replaces previous fork PR: #416
1 parent c4cefe9 commit 7a10e0d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

integration/tests/posit/connect/test_content.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ def test_count(self):
2323
assert self.client.content.count() == 1
2424

2525
def test_get(self):
26-
assert self.client.content.get(self.content["guid"]) == self.content
26+
item = self.client.content.get(self.content["guid"])
27+
# Check that essential fields match instead of exact equality
28+
for key in self.content:
29+
assert key in item
30+
assert item[key] == self.content[key]
31+
if CONNECT_VERSION >= version.parse("2024.06.0"):
32+
# get() always includes owner, tags, and vanity_url. Owner data is always present in
33+
# all content, tags and vanity_url are only present if explicitly set in the content.
34+
assert "owner" in item
35+
assert "tags" not in item
36+
assert "vanity_url" not in item
2737

2838
def test_find(self):
2939
assert self.client.content.find()

src/posit/connect/content.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,14 @@ def get(self, guid: str) -> ContentItem:
989989
Parameters
990990
----------
991991
guid : str
992+
The unique identifier of the content item.
992993
993994
Returns
994995
-------
995996
ContentItem
996997
"""
997-
response = self._ctx.client.get(f"v1/content/{guid}")
998+
# Always request all available optional fields for the content item
999+
params = {"include": "owner,tags,vanity_url"}
1000+
1001+
response = self._ctx.client.get(f"v1/content/{guid}", params=params)
9981002
return ContentItem(self._ctx, **response.json())

tests/posit/connect/test_content.py

Lines changed: 4 additions & 2 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",
@@ -326,7 +326,7 @@ def test_name(self):
326326
assert content_item["name"] == name
327327

328328
@responses.activate
329-
def test_params_include(self):
329+
def test_params_include_string(self):
330330
# behavior
331331
mock_get = responses.get(
332332
"https://connect.example/__api__/v1/content",
@@ -365,9 +365,11 @@ def test_params_include_none(self):
365365
class TestContentsGet:
366366
@responses.activate
367367
def test(self):
368+
# All calls to get() should automatically include all available optional fields
368369
responses.get(
369370
"https://connect.example/__api__/v1/content/f2f37341-e21d-3d80-c698-a935ad614066",
370371
json=load_mock("v1/content/f2f37341-e21d-3d80-c698-a935ad614066.json"),
372+
match=[matchers.query_param_matcher({"include": "owner,tags,vanity_url"})],
371373
)
372374
con = Client("https://connect.example", "12345")
373375
get_one = con.content.get("f2f37341-e21d-3d80-c698-a935ad614066")

0 commit comments

Comments
 (0)