Skip to content

Commit

Permalink
feat!: removes filter parameter from content.find and content.find_on…
Browse files Browse the repository at this point in the history
…e. (#129)

BREAKING CHANGE: Support for passing a filter as lambda expression to
content.find and content.find_one is removed. Please use client side
filtering instead. Additional filter support is planned for a future
release.
  • Loading branch information
tdstein authored Mar 22, 2024
1 parent 9102f50 commit 22d7373
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
22 changes: 9 additions & 13 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Callable, List, Optional, overload
from typing import List, Optional, overload


from requests import Session
Expand Down Expand Up @@ -285,9 +285,7 @@ def __init__(self, config: Config, session: Session) -> None:
self.config = config
self.session = session

def find(
self, filter: Callable[[ContentItem], bool] = lambda _: True
) -> List[ContentItem]:
def find(self) -> List[ContentItem]:
results = self.session.get(self.url).json()
items = (
ContentItem(
Expand All @@ -297,21 +295,19 @@ def find(
)
for result in results
)
return [item for item in items if filter(item)]
return [item for item in items]

def find_one(
self, filter: Callable[[ContentItem], bool] = lambda _: True
) -> ContentItem | None:
def find_one(self) -> ContentItem | None:
results = self.session.get(self.url).json()
for result in results:
item = ContentItem(
items = (
ContentItem(
config=self.config,
session=self.session,
**result,
)
if filter(item):
return item
return None
for result in results
)
return next(items, None)

def get(self, id: str) -> ContentItem:
url = urls.append_path(self.url, id)
Expand Down
7 changes: 2 additions & 5 deletions tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ def test_content_find_one(self):
)
con = Client("12345", "https://connect.example")

one = con.content.find_one(lambda c: c.title == "Performance Data")
one = con.content.find_one()
assert isinstance(one, ContentItem)
assert one.name == "Performance-Data-1671216053560"

# Test find_one doesn't find any
assert con.content.find_one(lambda c: c.title == "Does not exist") is None
assert one.name == "team-admin-dashboard"

@responses.activate
def test_content_get(self):
Expand Down

0 comments on commit 22d7373

Please sign in to comment.