mirror of
https://github.com/home-assistant/core.git
synced 2026-05-03 19:41:15 +02:00
Fix steamist tests opening sockets (#156467)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"""Test fixtures for the Steamist integration."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_aio_discovery() -> Generator[MagicMock]:
|
||||
"""Mock AIODiscovery30303."""
|
||||
with patch(
|
||||
"homeassistant.components.steamist.discovery.AIODiscovery30303"
|
||||
) as mock_aio_discovery:
|
||||
mock_aio_discovery.return_value.async_scan = AsyncMock()
|
||||
yield mock_aio_discovery
|
||||
@@ -42,6 +42,7 @@ def mock_single_broadcast_address():
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aio_discovery")
|
||||
async def test_config_entry_reload(hass: HomeAssistant) -> None:
|
||||
"""Test that a config entry can be reloaded."""
|
||||
_, config_entry = await _async_setup_entry_with_status(
|
||||
@@ -52,6 +53,7 @@ async def test_config_entry_reload(hass: HomeAssistant) -> None:
|
||||
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aio_discovery")
|
||||
async def test_config_entry_retry_later(hass: HomeAssistant) -> None:
|
||||
"""Test that a config entry retry on connection error."""
|
||||
config_entry = MockConfigEntry(
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@@ -12,6 +14,7 @@ from . import (
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aio_discovery")
|
||||
async def test_steam_active(hass: HomeAssistant) -> None:
|
||||
"""Test that the sensors are setup with the expected values when steam is active."""
|
||||
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
|
||||
@@ -23,6 +26,7 @@ async def test_steam_active(hass: HomeAssistant) -> None:
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aio_discovery")
|
||||
async def test_steam_inactive(hass: HomeAssistant) -> None:
|
||||
"""Test that the sensors are setup with the expected values when steam is not active."""
|
||||
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_INACTIVE)
|
||||
|
||||
@@ -5,6 +5,8 @@ from __future__ import annotations
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -19,6 +21,7 @@ from . import (
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aio_discovery")
|
||||
async def test_steam_active(hass: HomeAssistant) -> None:
|
||||
"""Test that the switches are setup with the expected values when steam is active."""
|
||||
client, _ = await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
|
||||
@@ -38,6 +41,7 @@ async def test_steam_active(hass: HomeAssistant) -> None:
|
||||
assert hass.states.get("switch.steam_active").state == STATE_OFF
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aio_discovery")
|
||||
async def test_steam_inactive(hass: HomeAssistant) -> None:
|
||||
"""Test that the switches are setup with the expected values when steam is not active."""
|
||||
client, _ = await _async_setup_entry_with_status(
|
||||
|
||||
Reference in New Issue
Block a user