Skip to content

Commit 8d236b1

Browse files
committed
Refactor so get() is hard coded to always use all include fields
1 parent 980d68c commit 8d236b1

File tree

3 files changed

+16
-74
lines changed

3 files changed

+16
-74
lines changed

integration/tests/posit/connect/test_content.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +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
27-
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-
)
26+
item = self.client.content.get(self.content["guid"])
27+
# get() always includes owner, tags, and vanity_url. Owner data is always present in all
28+
# content, tags and vanity_url is only present if explicitly set in the content.
29+
# Check that essential fields match instead of exact equality
30+
for key in self.content:
31+
assert key in item
32+
assert item[key] == self.content[key]
33+
# Also verify we have the additional fields that should always be included
34+
assert "owner" in item
35+
assert "tags" not in item
36+
assert "vanity_url" not in item
3537

3638
def test_find(self):
3739
assert self.client.content.find()

src/posit/connect/content.py

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

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:
986+
def get(self, guid: str) -> ContentItem:
994987
"""Get a content item.
995988
996989
Parameters
997990
----------
998991
guid : str
999992
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'.
1003993
1004994
Returns
1005995
-------
1006996
ContentItem
1007997
"""
1008-
params = {}
1009-
if include is not None:
1010-
if isinstance(include, list):
1011-
params["include"] = ",".join(include)
1012-
else:
1013-
params["include"] = include
998+
# Always request all available optional fields for the content item
999+
params = {"include": "owner,tags,vanity_url"}
10141000

10151001
response = self._ctx.client.get(f"v1/content/{guid}", params=params)
10161002
return ContentItem(self._ctx, **response.json())

tests/posit/connect/test_content.py

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -365,62 +365,16 @@ 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")
374376
assert get_one["name"] == "Performance-Data-1671216053560"
375377

376-
@responses.activate
377-
def test_params_include_string(self):
378-
guid = "f2f37341-e21d-3d80-c698-a935ad614066"
379-
mock_get = responses.get(
380-
f"https://connect.example/__api__/v1/content/{guid}",
381-
json=load_mock(f"v1/content/{guid}.json"),
382-
match=[matchers.query_param_matcher({"include": "owner"})],
383-
)
384-
385-
con = Client("https://connect.example", "12345")
386-
content = con.content.get(guid, include="owner")
387-
assert content["guid"] == guid
388-
389-
# assert
390-
assert mock_get.call_count == 1
391-
392-
@responses.activate
393-
def test_params_include_list(self):
394-
guid = "f2f37341-e21d-3d80-c698-a935ad614066"
395-
mock_get = responses.get(
396-
f"https://connect.example/__api__/v1/content/{guid}",
397-
json=load_mock(f"v1/content/{guid}.json"),
398-
match=[matchers.query_param_matcher({"include": "owner,tags,vanity_url"})],
399-
)
400-
401-
con = Client("https://connect.example", "12345")
402-
content = con.content.get(guid, include=["owner", "tags", "vanity_url"])
403-
assert content["guid"] == guid
404-
405-
# assert
406-
assert mock_get.call_count == 1
407-
408-
@responses.activate
409-
def test_params_include_none(self):
410-
guid = "f2f37341-e21d-3d80-c698-a935ad614066"
411-
mock_get = responses.get(
412-
f"https://connect.example/__api__/v1/content/{guid}",
413-
json=load_mock(f"v1/content/{guid}.json"),
414-
match=[matchers.query_param_matcher({})],
415-
)
416-
417-
con = Client("https://connect.example", "12345")
418-
content = con.content.get(guid, include=None)
419-
assert content["guid"] == guid
420-
421-
# assert
422-
assert mock_get.call_count == 1
423-
424378

425379
class TestContentsCount:
426380
@responses.activate

0 commit comments

Comments
 (0)