Replace deprecated aiohttp_unused_port fixture (#97626)

This commit is contained in:
Marc Mueller 2023-08-02 20:30:13 +02:00 committed by GitHub
parent 91a83e1ad2
commit 887e48c440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View file

@ -85,11 +85,13 @@ class TestView(http.HomeAssistantView):
async def test_registering_view_while_running(
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, aiohttp_unused_port
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, unused_tcp_port_factory
) -> None:
"""Test that we can register a view while the server is running."""
await async_setup_component(
hass, http.DOMAIN, {http.DOMAIN: {http.CONF_SERVER_PORT: aiohttp_unused_port()}}
hass,
http.DOMAIN,
{http.DOMAIN: {http.CONF_SERVER_PORT: unused_tcp_port_factory()}},
)
await hass.async_start()
@ -443,11 +445,11 @@ async def test_cors_defaults(hass: HomeAssistant) -> None:
async def test_storing_config(
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, aiohttp_unused_port
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator, unused_tcp_port_factory
) -> None:
"""Test that we store last working config."""
config = {
http.CONF_SERVER_PORT: aiohttp_unused_port(),
http.CONF_SERVER_PORT: unused_tcp_port_factory(),
"use_x_forwarded_for": True,
"trusted_proxies": ["192.168.1.100"],
}

View file

@ -23,9 +23,9 @@ async def setup_homeassistant(hass: HomeAssistant):
@pytest.fixture
def aiohttp_unused_port(event_loop, aiohttp_unused_port, socket_enabled):
def aiohttp_unused_port_factory(event_loop, unused_tcp_port_factory, socket_enabled):
"""Return aiohttp_unused_port and allow opening sockets."""
return aiohttp_unused_port
return unused_tcp_port_factory
def get_url(hass):
@ -34,12 +34,12 @@ def get_url(hass):
return f"{hass.config.internal_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
async def setup_image_processing(hass, aiohttp_unused_port):
async def setup_image_processing(hass, aiohttp_unused_port_factory):
"""Set up things to be run when tests are started."""
await async_setup_component(
hass,
http.DOMAIN,
{http.DOMAIN: {http.CONF_SERVER_PORT: aiohttp_unused_port()}},
{http.DOMAIN: {http.CONF_SERVER_PORT: aiohttp_unused_port_factory()}},
)
config = {ip.DOMAIN: {"platform": "test"}, "camera": {"platform": "demo"}}
@ -85,11 +85,11 @@ async def test_setup_component_with_service(hass: HomeAssistant) -> None:
async def test_get_image_from_camera(
mock_camera_read,
hass: HomeAssistant,
aiohttp_unused_port,
aiohttp_unused_port_factory,
enable_custom_integrations: None,
) -> None:
"""Grab an image from camera entity."""
await setup_image_processing(hass, aiohttp_unused_port)
await setup_image_processing(hass, aiohttp_unused_port_factory)
common.async_scan(hass, entity_id="image_processing.test")
await hass.async_block_till_done()
@ -108,11 +108,11 @@ async def test_get_image_from_camera(
async def test_get_image_without_exists_camera(
mock_image,
hass: HomeAssistant,
aiohttp_unused_port,
aiohttp_unused_port_factory,
enable_custom_integrations: None,
) -> None:
"""Try to get image without exists camera."""
await setup_image_processing(hass, aiohttp_unused_port)
await setup_image_processing(hass, aiohttp_unused_port_factory)
hass.states.async_remove("camera.demo_camera")