Deprecated hass.http.register_static_path now raises error (#147039)

This commit is contained in:
G Johansson
2025-06-19 13:14:42 +02:00
committed by GitHub
parent 513045e489
commit c602a0e279
3 changed files with 14 additions and 12 deletions

View File

@@ -16,6 +16,7 @@ from aiohttp.hdrs import (
from aiohttp.test_utils import TestClient
import pytest
from homeassistant.components.http import StaticPathConfig
from homeassistant.components.http.cors import setup_cors
from homeassistant.core import HomeAssistant
from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS, HomeAssistantView
@@ -157,7 +158,9 @@ async def test_cors_on_static_files(
assert await async_setup_component(
hass, "frontend", {"http": {"cors_allowed_origins": ["http://www.example.com"]}}
)
hass.http.register_static_path("/something", str(Path(__file__).parent))
await hass.http.async_register_static_paths(
[StaticPathConfig("/something", str(Path(__file__).parent))]
)
client = await hass_client()
resp = await client.options(

View File

@@ -530,17 +530,14 @@ async def test_register_static_paths(
"""Test registering a static path with old api."""
assert await async_setup_component(hass, "frontend", {})
path = str(Path(__file__).parent)
hass.http.register_static_path("/something", path)
client = await hass_client()
resp = await client.get("/something/__init__.py")
assert resp.status == HTTPStatus.OK
assert (
match_error = (
"Detected code that calls hass.http.register_static_path "
"which is deprecated because it does blocking I/O in the "
"event loop, instead call "
"which does blocking I/O in the event loop, instead call "
"`await hass.http.async_register_static_paths"
) in caplog.text
)
with pytest.raises(RuntimeError, match=match_error):
hass.http.register_static_path("/something", path)
async def test_ssl_issue_if_no_urls_configured(