Skip to content

Commit

Permalink
Add new method to fetch category entry and entries
Browse files Browse the repository at this point in the history
Additionally:
 - changed the `get_category_feeds` argument from `feed_id` to `category_id`
   as it seems more correct name (matching one in go code)
 - added missing test for `get_feed_entry`
  • Loading branch information
tanelpuhu committed Sep 5, 2023
1 parent e43b483 commit 9e50e27
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
27 changes: 25 additions & 2 deletions miniflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def discover(self, website_url: str, **kwargs) -> Dict:
return response.json()
raise ClientError(response)

def get_category_feeds(self, feed_id: int) -> List[Dict]:
endpoint = self._get_endpoint(f"/categories/{feed_id}/feeds")
def get_category_feeds(self, category_id: int) -> List[Dict]:
endpoint = self._get_endpoint(f"/categories/{category_id}/feeds")
response = requests.get(
endpoint, headers=self._headers, auth=self._auth, timeout=self._timeout
)
Expand Down Expand Up @@ -333,6 +333,29 @@ def get_categories(self) -> List[Dict]:
return response.json()
raise ClientError(response)

def get_category_entry(self, category_id: int, entry_id: int) -> Dict:
endpoint = self._get_endpoint(f"/categories/{category_id}/entries/{entry_id}")
response = requests.get(
endpoint, headers=self._headers, auth=self._auth, timeout=self._timeout
)
if response.status_code == 200:
return response.json()
raise ClientError(response)

def get_category_entries(self, category_id: int, **kwargs) -> Dict:
endpoint = self._get_endpoint(f"/categories/{category_id}/entries")
params = self._get_params(**kwargs)
response = requests.get(
endpoint,
headers=self._headers,
auth=self._auth,
params=params,
timeout=self._timeout,
)
if response.status_code == 200:
return response.json()
raise ClientError(response)

def create_category(self, title: str) -> Dict:
endpoint = self._get_endpoint("/categories")
data = {"title": title}
Expand Down
67 changes: 67 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ def test_refresh_category(self):

assert result == expected_result

def test_get_feed_entry(self):
requests = _get_request_mock()
expected_result = {}

response = mock.Mock()
response.status_code = 200
response.json.return_value = expected_result

requests.get.return_value = response

client = miniflux.Client("http://localhost", "username", "password")
result = client.get_feed_entry(123, 456)

requests.get.assert_called_once_with(
"http://localhost/v1/feeds/123/entries/456",
headers=None,
auth=("username", "password"),
timeout=30,
)

assert result == expected_result

def test_get_feed_entries(self):
requests = _get_request_mock()
expected_result = []
Expand Down Expand Up @@ -874,6 +896,51 @@ def test_save_entry(self):
)
assert result == expected_result

def test_get_category_entry(self):
requests = _get_request_mock()
expected_result = {}

response = mock.Mock()
response.status_code = 200
response.json.return_value = expected_result

requests.get.return_value = response

client = miniflux.Client("http://localhost", "username", "password")
result = client.get_category_entry(123, 456)

requests.get.assert_called_once_with(
"http://localhost/v1/categories/123/entries/456",
headers=None,
auth=("username", "password"),
timeout=30,
)

assert result == expected_result

def test_get_category_entries(self):
requests = _get_request_mock()
expected_result = []

response = mock.Mock()
response.status_code = 200
response.json.return_value = expected_result

requests.get.return_value = response

client = miniflux.Client("http://localhost", "username", "password")
result = client.get_category_entries(123)

requests.get.assert_called_once_with(
"http://localhost/v1/categories/123/entries",
headers=None,
auth=("username", "password"),
params=None,
timeout=30,
)

assert result == expected_result


def _get_request_mock():
patcher = mock.patch("miniflux.requests")
Expand Down

0 comments on commit 9e50e27

Please sign in to comment.