From c05984ca49f6e53a115bfadb61673f5e8f58a07f Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Tue, 7 May 2024 04:41:16 -0400 Subject: [PATCH] Fix no changelog API response (#5064) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix no changelog API response * Add comment reasoning HTTP 200 for no changelog Co-authored-by: Stefan Agner * Apply suggestions from code review Co-authored-by: Jan Čermák --------- Co-authored-by: Jan Čermák Co-authored-by: Stefan Agner --- supervisor/api/__init__.py | 3 ++- supervisor/api/store.py | 2 +- tests/api/test_store.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index e91c0383a..8de11af0e 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -697,7 +697,6 @@ class RestAPI(CoreSysAttributes): web.get("/store", api_store.store_info), web.get("/store/addons", api_store.addons_list), web.get("/store/addons/{addon}", api_store.addons_addon_info), - web.get("/store/addons/{addon}/{version}", api_store.addons_addon_info), web.get("/store/addons/{addon}/icon", api_store.addons_addon_icon), web.get("/store/addons/{addon}/logo", api_store.addons_addon_logo), web.get( @@ -719,6 +718,8 @@ class RestAPI(CoreSysAttributes): "/store/addons/{addon}/update/{version}", api_store.addons_addon_update, ), + # Must be below others since it has a wildcard in resource path + web.get("/store/addons/{addon}/{version}", api_store.addons_addon_info), web.post("/store/reload", api_store.reload), web.get("/store/repositories", api_store.repositories_list), web.get( diff --git a/supervisor/api/store.py b/supervisor/api/store.py index a3a09b81e..d82834685 100644 --- a/supervisor/api/store.py +++ b/supervisor/api/store.py @@ -251,7 +251,7 @@ class APIStore(CoreSysAttributes): """Return changelog from add-on.""" addon = self._extract_addon(request) if not addon.with_changelog: - raise APIError(f"No changelog found for add-on {addon.slug}!") + return f"No changelog found for add-on {addon.slug}!" with addon.path_changelog.open("r") as changelog: return changelog.read() diff --git a/tests/api/test_store.py b/tests/api/test_store.py index c0c4e4d7f..4dc88f1a4 100644 --- a/tests/api/test_store.py +++ b/tests/api/test_store.py @@ -188,3 +188,18 @@ async def test_api_store_update_healthcheck( assert resp.status == 200 await _container_events_task + + +@pytest.mark.parametrize("resource", ["store/addons", "addons"]) +async def test_api_store_addons_no_changelog( + api_client: TestClient, coresys: CoreSys, store_addon: AddonStore, resource: str +): + """Test /store/addons/{addon}/changelog REST API. + + Currently the frontend expects a valid body even in the error case. Make sure that is + what the API returns. + """ + resp = await api_client.get(f"/{resource}/{store_addon.slug}/changelog") + assert resp.status == 200 + result = await resp.text() + assert result == "No changelog found for add-on test_store_addon!"