core/tests/components/ssdp/conftest.py
J. Nick Koston d4c1d1bdb9
Split up SSDP integration into modules (#143732)
* Split up SSDP integration into modules

* Split up SSDP integration into modules

* migrate tests
2025-04-26 18:09:51 -04:00

44 lines
1.5 KiB
Python

"""Configuration for SSDP tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from async_upnp_client.server import UpnpServer
from async_upnp_client.ssdp_listener import SsdpListener
import pytest
from homeassistant.core import HomeAssistant
@pytest.fixture(autouse=True)
async def silent_ssdp_listener():
"""Patch SsdpListener class, preventing any actual SSDP traffic."""
with (
patch("homeassistant.components.ssdp.scanner.SsdpListener.async_start"),
patch("homeassistant.components.ssdp.scanner.SsdpListener.async_stop"),
patch("homeassistant.components.ssdp.scanner.SsdpListener.async_search"),
):
# Fixtures are initialized before patches. When the component is started here,
# certain functions/methods might not be patched in time.
yield SsdpListener
@pytest.fixture(autouse=True)
async def disabled_upnp_server():
"""Disable UPnpServer."""
with (
patch("homeassistant.components.ssdp.server.UpnpServer.async_start"),
patch("homeassistant.components.ssdp.server.UpnpServer.async_stop"),
patch("homeassistant.components.ssdp.server._async_find_next_available_port"),
):
yield UpnpServer
@pytest.fixture
def mock_flow_init(hass: HomeAssistant) -> Generator[AsyncMock]:
"""Mock hass.config_entries.flow.async_init."""
with patch.object(
hass.config_entries.flow, "async_init", return_value=AsyncMock()
) as mock_init:
yield mock_init