mirror of https://github.com/home-assistant/core
44 lines
1.4 KiB
Python
44 lines
1.4 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.SsdpListener.async_start"),
|
|
patch("homeassistant.components.ssdp.SsdpListener.async_stop"),
|
|
patch("homeassistant.components.ssdp.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.UpnpServer.async_start"),
|
|
patch("homeassistant.components.ssdp.UpnpServer.async_stop"),
|
|
patch("homeassistant.components.ssdp._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
|