diff --git a/src/posit/connect/content.py b/src/posit/connect/content.py index e1d964bf..b5bd9a7c 100644 --- a/src/posit/connect/content.py +++ b/src/posit/connect/content.py @@ -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 @@ -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( @@ -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) diff --git a/tests/posit/connect/test_content.py b/tests/posit/connect/test_content.py index 72030a95..f9dc0263 100644 --- a/tests/posit/connect/test_content.py +++ b/tests/posit/connect/test_content.py @@ -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):