From 2f55ce2b1e32ba1d898369829ade21406563c734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sun, 8 Oct 2023 15:51:38 -0700 Subject: [PATCH] Use /v1/version endpoint instead of /version --- miniflux.py | 10 ++++++---- tests/test_client.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/miniflux.py b/miniflux.py index 0b49bdb..c8ed59b 100644 --- a/miniflux.py +++ b/miniflux.py @@ -71,11 +71,13 @@ def _get_params(self, **kwargs) -> Optional[Dict]: def _get_modification_params(self, **kwargs) -> Dict: return {k: v for k, v in kwargs.items() if v is not None} - def get_version(self) -> str: - endpoint = f"{self._base_url}/version" - response = requests.get(endpoint, timeout=self._timeout) + def get_version(self) -> Dict: + endpoint = self._get_endpoint("/version") + response = requests.get( + endpoint, headers=self._headers, auth=self._auth, timeout=self._timeout + ) if response.status_code == 200: - return response.text + return response.json() raise ClientError(response) def me(self) -> Dict: diff --git a/tests/test_client.py b/tests/test_client.py index da2b274..42fd6a1 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -80,6 +80,36 @@ def test_base_url_with_trailing_slash(self): self.assertEqual(result, expected_result) + def test_get_version(self): + requests = _get_request_mock() + expected_result = { + "version": "dev", + "commit": "HEAD", + "build_date": "undefined", + "go_version": "go1.21.1", + "compiler": "gc", + "arch": "amd64", + "os": "darwin" + } + + response = mock.Mock() + response.status_code = 200 + response.json.return_value = expected_result + + requests.get.return_value = response + + client = miniflux.Client("http://localhost", api_key="secret") + result = client.get_version() + + requests.get.assert_called_once_with( + "http://localhost/v1/version", + headers={"X-Auth-Token": "secret"}, + auth=None, + timeout=30.0, + ) + + self.assertEqual(result, expected_result) + def test_get_me(self): requests = _get_request_mock() expected_result = {"id": 123, "username": "foobar"}