Skip to content

Extend content.get() to support include param #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion integration/tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ def test_count(self):
assert self.client.content.count() == 1

def test_get(self):
assert self.client.content.get(self.content["guid"]) == self.content
item = self.client.content.get(self.content["guid"])
# get() always includes owner, tags, and vanity_url. Owner data is always present in all
# content, tags and vanity_url is only present if explicitly set in the content.
# Check that essential fields match instead of exact equality
for key in self.content:
assert key in item
assert item[key] == self.content[key]
# Also verify we have the additional fields that should always be included
assert "owner" in item
assert "tags" not in item
assert "vanity_url" not in item

def test_find(self):
assert self.client.content.find()
Expand Down
6 changes: 5 additions & 1 deletion src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,14 @@ def get(self, guid: str) -> ContentItem:
Parameters
----------
guid : str
The unique identifier of the content item.

Returns
-------
ContentItem
"""
response = self._ctx.client.get(f"v1/content/{guid}")
# Always request all available optional fields for the content item
params = {"include": "owner,tags,vanity_url"}

response = self._ctx.client.get(f"v1/content/{guid}", params=params)
return ContentItem(self._ctx, **response.json())
6 changes: 4 additions & 2 deletions tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test(self):
assert content[2]["name"] == "My-Streamlit-app"

@responses.activate
def test_params_include(self):
def test_params_include_string(self):
# behavior
mock_get = responses.get(
"https://connect.example/__api__/v1/content",
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_name(self):
assert content_item["name"] == name

@responses.activate
def test_params_include(self):
def test_params_include_string(self):
# behavior
mock_get = responses.get(
"https://connect.example/__api__/v1/content",
Expand Down Expand Up @@ -365,9 +365,11 @@ def test_params_include_none(self):
class TestContentsGet:
@responses.activate
def test(self):
# All calls to get() should automatically include all available optional fields
responses.get(
"https://connect.example/__api__/v1/content/f2f37341-e21d-3d80-c698-a935ad614066",
json=load_mock("v1/content/f2f37341-e21d-3d80-c698-a935ad614066.json"),
match=[matchers.query_param_matcher({"include": "owner,tags,vanity_url"})],
)
con = Client("https://connect.example", "12345")
get_one = con.content.get("f2f37341-e21d-3d80-c698-a935ad614066")
Expand Down
Loading