Skip to content

Commit

Permalink
Add get_icon() and get_icon_by_feed_id() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Oct 8, 2023
1 parent 1fe1328 commit 7882c6f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
12 changes: 12 additions & 0 deletions miniflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ def get_feed_icon(self, feed_id: int) -> Dict:
return response.json()
raise ClientError(response)

def get_icon(self, icon_id: int) -> Dict:
endpoint = self._get_endpoint(f"/icons/{icon_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_icon_by_feed_id(self, feed_id: int) -> Dict:
return self.get_feed_icon(feed_id)

def create_feed(self, feed_url: str, category_id: int, **kwargs) -> int:
endpoint = self._get_endpoint("/feeds")
data = dict(feed_url=feed_url, category_id=category_id)
Expand Down
52 changes: 52 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,58 @@ def test_get_feed(self):

self.assertEqual(result, expected_result)

def test_get_feed_icon(self):
requests = _get_request_mock()
expected_result = {
"id": 11,
"mime_type": "image/x-icon",
"data": "image/x-icon;base64,data",
}

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_icon_by_feed_id(123)

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

self.assertEqual(result, expected_result)

def test_get_icon(self):
requests = _get_request_mock()
expected_result = {
"id": 11,
"mime_type": "image/x-icon",
"data": "image/x-icon;base64,data",
}

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_icon(11)

requests.get.assert_called_once_with(
"http://localhost/v1/icons/11",
headers=None,
auth=("username", "password"),
timeout=30.0,
)

self.assertEqual(result, expected_result)

def test_create_feed(self):
requests = _get_request_mock()
expected_result = {"feed_id": 42}
Expand Down

0 comments on commit 7882c6f

Please sign in to comment.