Skip to content

Commit d705d92

Browse files
committed
Remove .content_items property from ChildTags and DescendantTags helper classes
1 parent ef4bc00 commit d705d92

File tree

2 files changed

+6
-156
lines changed

2 files changed

+6
-156
lines changed

integration/tests/posit/connect/test_tags.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,11 @@ def test_tag_content_items(self):
140140
assert len(tagC.content_items.find()) == 3
141141

142142
# Make sure unique content items are found
143-
assert len(tagB.child_tags.content_items.find()) == 0
144-
assert len(tagD.child_tags.content_items.find()) == 0
145-
assert len(tagB.descendant_tags.content_items.find()) == 0
146-
assert len(tagD.descendant_tags.content_items.find()) == 0
143+
content_items = tagA.content_items.find()
144+
assert len(content_items) == 3
147145

148-
child_content_items = tagC.child_tags.content_items.find()
149-
assert len(child_content_items) == 1
150-
child_content_item_guids = {content_item["guid"] for content_item in child_content_items}
151-
assert child_content_item_guids == {self.contentA["guid"]}
152-
153-
descendant_content_items = tagA.descendant_tags.content_items.find()
154-
assert len(descendant_content_items) == 3
155-
156-
descendant_content_item_guids = {
157-
content_item["guid"] for content_item in descendant_content_items
158-
}
159-
assert descendant_content_item_guids == {
146+
content_item_guids = {content_item["guid"] for content_item in content_items}
147+
assert content_item_guids == {
160148
self.contentA["guid"],
161149
self.contentB["guid"],
162150
self.contentC["guid"],
@@ -169,6 +157,7 @@ def test_tag_content_items(self):
169157
assert len(tagA.content_items.find()) == 0
170158
assert len(tagB.content_items.find()) == 0
171159
assert len(tagC.content_items.find()) == 0
160+
assert len(tagD.content_items.find()) == 0
172161

173162
# cleanup
174163
tagRoot.destroy()

src/posit/connect/tags.py

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,11 @@
1313

1414

1515
class _RelatedTagsBase(ContextManager, ABC):
16-
@property
17-
@abstractmethod
18-
def content_items(self) -> _TagContentItemsBase:
19-
pass
20-
2116
@abstractmethod
2217
def find(self) -> list[Tag]:
2318
pass
2419

2520

26-
class _TagContentItemsBase(ContextManager, ABC):
27-
@staticmethod
28-
def _unique_content_items(tags: list[Tag]) -> list[ContentItem]:
29-
content_items: list[ContentItem] = []
30-
content_items_seen: set[str] = set()
31-
32-
for tag in tags:
33-
tag_content_items = tag.content_items.find()
34-
35-
for content_item in tag_content_items:
36-
content_item_guid = content_item["guid"]
37-
38-
if content_item_guid not in content_items_seen:
39-
content_items.append(content_item)
40-
content_items_seen.add(content_item_guid)
41-
42-
return content_items
43-
44-
@abstractmethod
45-
def find(self) -> list[ContentItem]: ...
46-
47-
4821
class Tag(Active):
4922
"""Tag resource."""
5023

@@ -163,7 +136,7 @@ def destroy(self) -> None:
163136
self._ctx.session.delete(url)
164137

165138

166-
class TagContentItems(_TagContentItemsBase):
139+
class TagContentItems(ContextManager):
167140
def __init__(self, ctx: Context, path: str) -> None:
168141
super().__init__()
169142
self._ctx = ctx
@@ -205,29 +178,6 @@ def __init__(self, ctx: Context, path: str, /, *, parent_tag: Tag) -> None:
205178

206179
self._parent_tag = parent_tag
207180

208-
@property
209-
def content_items(self) -> ChildTagContentItems:
210-
"""
211-
Find all content items from the child tags.
212-
213-
Returns
214-
-------
215-
ChildTagContentItems
216-
Helper class that can `.find()` all content items that are tagged with a child tag.
217-
218-
Examples
219-
--------
220-
```python
221-
import posit
222-
223-
client = posit.connect.Client()
224-
mytag = client.tags.get("TAG_ID_HERE")
225-
226-
tagged_content_items = mytag.child_tags.content_items.find()
227-
```
228-
"""
229-
return ChildTagContentItems(self._ctx, self._path, parent_tag=self._parent_tag)
230-
231181
def find(self) -> list[Tag]:
232182
"""
233183
Find all child tags that are direct children of a single tag.
@@ -252,101 +202,12 @@ def find(self) -> list[Tag]:
252202
return child_tags
253203

254204

255-
class ChildTagContentItems(_TagContentItemsBase):
256-
def __init__(self, ctx: Context, path: str, /, *, parent_tag: Tag) -> None:
257-
super().__init__()
258-
self._ctx = ctx
259-
self._path = path
260-
self._parent_tag = parent_tag
261-
262-
def find(self) -> list[ContentItem]:
263-
"""
264-
Find all content items that are tagged with a child tag.
265-
266-
Returns
267-
-------
268-
list[ContentItem]
269-
List of content items that are tagged with a child tag.
270-
271-
Examples
272-
--------
273-
```python
274-
import posit
275-
276-
client = posit.connect.Client()
277-
mytag = client.tags.get("TAG_ID_HERE")
278-
279-
tagged_content_items = mytag.child_tags.content_items.find()
280-
```
281-
"""
282-
child_tags = self._parent_tag.child_tags.find()
283-
content_items = self._unique_content_items(child_tags)
284-
return content_items
285-
286-
287-
class DescendantTagContentItems(_TagContentItemsBase):
288-
def __init__(self, ctx: Context, /, *, parent_tag: Tag) -> None:
289-
super().__init__()
290-
self._ctx = ctx
291-
self._parent_tag = parent_tag
292-
293-
def find(self) -> list[ContentItem]:
294-
"""
295-
Find all content items that are tagged with a descendant tag.
296-
297-
Returns
298-
-------
299-
list[ContentItem]
300-
List of content items that are tagged with a descendant tag.
301-
302-
Examples
303-
--------
304-
```python
305-
import posit
306-
307-
client = posit.connect.Client()
308-
mytag = client.tags.get("TAG_ID_HERE")
309-
310-
tagged_content_items = mytag.descendant_tags.content_items.find()
311-
```
312-
"""
313-
descendant_tags = self._parent_tag.descendant_tags.find()
314-
content_items = self._unique_content_items(descendant_tags)
315-
return content_items
316-
317-
318205
class DescendantTags(_RelatedTagsBase):
319206
def __init__(self, ctx: Context, /, *, parent_tag: Tag) -> None:
320207
super().__init__()
321208
self._ctx = ctx
322209
self._parent_tag = parent_tag
323210

324-
@property
325-
def content_items(self) -> DescendantTagContentItems:
326-
"""
327-
Find all content items from the descendant tags.
328-
329-
Returns
330-
-------
331-
DescendantTagContentItems
332-
Helper class that can `.find()` all content items that are tagged with a descendant tag.
333-
334-
Examples
335-
--------
336-
```python
337-
import posit
338-
339-
client = posit.connect.Client()
340-
mytag = client.tags.find(id="TAG_ID_HERE")
341-
342-
tagged_content_items = mytag.descendant_tags.content_items.find()
343-
```
344-
"""
345-
return DescendantTagContentItems(
346-
self._ctx,
347-
parent_tag=self._parent_tag,
348-
)
349-
350211
def find(self) -> list[Tag]:
351212
"""
352213
Find all child tags that descend from a single tag.

0 commit comments

Comments
 (0)