diff --git a/supervisor/api/store.py b/supervisor/api/store.py index 92c58a69b58..82e14627f55 100644 --- a/supervisor/api/store.py +++ b/supervisor/api/store.py @@ -76,13 +76,16 @@ def _extract_addon(self, request: web.Request, installed=False) -> AnyAddon: addon_slug: str = request.match_info.get("addon") if not (addon := self.sys_addons.get(addon_slug)): - raise APINotFound(f"Addon {addon_slug} does not exist in the store") + raise APINotFound(f"Addon {addon_slug} does not exist") if installed and not addon.is_installed: raise APIError(f"Addon {addon_slug} is not installed") if not installed and addon.is_installed: + if not addon.addon_store: + raise APINotFound(f"Addon {addon_slug} does not exist in the store") return addon.addon_store + return addon def _extract_repository(self, request: web.Request) -> Repository: diff --git a/tests/api/test_jobs.py b/tests/api/test_jobs.py index 298f350d911..00e798e227b 100644 --- a/tests/api/test_jobs.py +++ b/tests/api/test_jobs.py @@ -216,7 +216,7 @@ async def test_job_manual_cleanup(self) -> None: resp = await api_client.get(f"/jobs/{test.job_id}") assert resp.status == 404 result = await resp.json() - assert result["message"] == f"No job found with id {test.job_id}" + assert result["message"] == "Job does not exist" @pytest.mark.parametrize( diff --git a/tests/api/test_mounts.py b/tests/api/test_mounts.py index 367c7c33d90..e22dcbb8763 100644 --- a/tests/api/test_mounts.py +++ b/tests/api/test_mounts.py @@ -264,25 +264,6 @@ async def test_api_update_mount( coresys.mounts.save_data.assert_called_once() -async def test_api_update_error_mount_missing( - api_client: TestClient, mount_propagation -): - """Test update mount API errors when mount does not exist.""" - resp = await api_client.put( - "/mounts/backup_test", - json={ - "type": "cifs", - "usage": "backup", - "server": "backup.local", - "share": "new_backups", - }, - ) - assert resp.status == 400 - result = await resp.json() - assert result["result"] == "error" - assert result["message"] == "No mount exists with name backup_test" - - async def test_api_update_dbus_error_mount_remains( api_client: TestClient, all_dbus_services: dict[str, DBusServiceMock], @@ -399,20 +380,6 @@ async def test_api_reload_mount( ] -async def test_api_reload_error_mount_missing( - api_client: TestClient, mount_propagation -): - """Test reload mount API errors when mount does not exist.""" - resp = await api_client.post("/mounts/backup_test/reload") - assert resp.status == 400 - result = await resp.json() - assert result["result"] == "error" - assert ( - result["message"] - == "Cannot reload 'backup_test', no mount exists with that name" - ) - - async def test_api_delete_mount( api_client: TestClient, coresys: CoreSys, @@ -435,20 +402,6 @@ async def test_api_delete_mount( coresys.mounts.save_data.assert_called_once() -async def test_api_delete_error_mount_missing( - api_client: TestClient, mount_propagation -): - """Test delete mount API errors when mount does not exist.""" - resp = await api_client.delete("/mounts/backup_test") - assert resp.status == 400 - result = await resp.json() - assert result["result"] == "error" - assert ( - result["message"] - == "Cannot remove 'backup_test', no mount exists with that name" - ) - - async def test_api_create_backup_mount_sets_default( api_client: TestClient, coresys: CoreSys, @@ -903,3 +856,19 @@ async def test_api_read_only_backup_mount_invalid( result = await resp.json() assert result["result"] == "error" assert "Backup mounts cannot be read only" in result["message"] + + +@pytest.mark.parametrize( + ("method", "url"), + [ + ("put", "/mounts/bad"), + ("delete", "/mounts/bad"), + ("post", "/mounts/bad/reload"), + ], +) +async def test_mount_not_found(api_client: TestClient, method: str, url: str): + """Test mount not found error.""" + resp = await api_client.request(method, url) + assert resp.status == 404 + resp = await resp.json() + assert resp["message"] == "No mount exists with name bad" diff --git a/tests/api/test_store.py b/tests/api/test_store.py index f571c2ad8fb..0a11df9b02a 100644 --- a/tests/api/test_store.py +++ b/tests/api/test_store.py @@ -236,7 +236,7 @@ async def test_api_detached_addon_changelog( resp = await api_client.get(f"/{resource}/{install_addon_ssh.slug}/changelog") assert resp.status == 200 result = await resp.text() - assert result == "Addon local_ssh with version latest does not exist in the store" + assert result == "Addon local_ssh does not exist in the store" @pytest.mark.parametrize("resource", ["store/addons", "addons"]) @@ -280,7 +280,7 @@ async def test_api_detached_addon_documentation( resp = await api_client.get(f"/{resource}/{install_addon_ssh.slug}/documentation") assert resp.status == 200 result = await resp.text() - assert result == "Addon local_ssh with version latest does not exist in the store" + assert result == "Addon local_ssh does not exist in the store" async def get_message(resp: ClientResponse, json_expected: bool) -> str: @@ -315,10 +315,7 @@ async def test_store_addon_not_found( """Test store addon not found error.""" resp = await api_client.request(method, url) assert resp.status == 404 - assert ( - await get_message(resp, json_expected) - == "Addon bad does not exist in the store" - ) + assert await get_message(resp, json_expected) == "Addon bad does not exist" @pytest.mark.parametrize(