Pump pysaunum to 0.2.0 (#160668)

This commit is contained in:
mettolen
2026-01-11 16:14:45 +01:00
committed by GitHub
parent 153278221d
commit 72655dbf0b
9 changed files with 33 additions and 26 deletions
+12 -4
View File
@@ -2,7 +2,7 @@
from collections.abc import Generator
from datetime import timedelta
from unittest.mock import MagicMock, patch
from unittest.mock import AsyncMock, MagicMock, patch
from pysaunum import SaunumData
import pytest
@@ -42,8 +42,8 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture
def mock_saunum_client() -> Generator[MagicMock]:
"""Return a mocked Saunum client for config flow and integration tests."""
def mock_saunum_client_class() -> Generator[MagicMock]:
"""Return a mocked Saunum client class for config flow and integration tests."""
with (
patch(
"homeassistant.components.saunum.config_flow.SaunumClient", autospec=True
@@ -53,6 +53,8 @@ def mock_saunum_client() -> Generator[MagicMock]:
mock_client = mock_client_class.return_value
mock_client.is_connected = True
mock_client_class.create = AsyncMock(return_value=mock_client)
# Create mock data for async_get_data
mock_data = SaunumData(
session_active=False,
@@ -76,7 +78,13 @@ def mock_saunum_client() -> Generator[MagicMock]:
mock_client.async_get_data.return_value = mock_data
yield mock_client
yield mock_client_class
@pytest.fixture
def mock_saunum_client(mock_saunum_client_class: MagicMock) -> MagicMock:
"""Return a mocked Saunum client instance."""
return mock_saunum_client_class.return_value
@pytest.fixture
+8 -9
View File
@@ -49,14 +49,13 @@ async def test_full_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
)
async def test_form_errors(
hass: HomeAssistant,
mock_saunum_client,
mock_saunum_client_class,
side_effect: Exception,
error_base: str,
mock_setup_entry: AsyncMock,
) -> None:
"""Test error handling and recovery."""
mock_saunum_client.connect.side_effect = side_effect
mock_saunum_client_class.create.side_effect = side_effect
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
@@ -69,8 +68,8 @@ async def test_form_errors(
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": error_base}
# Test recovery - clear the error and try again
mock_saunum_client.connect.side_effect = None
# Test recovery - try again without the error
mock_saunum_client_class.create.side_effect = None
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -139,20 +138,20 @@ async def test_reconfigure_flow(
async def test_reconfigure_errors(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_saunum_client,
mock_saunum_client_class,
side_effect: Exception,
error_base: str,
mock_setup_entry: AsyncMock,
) -> None:
"""Test reconfigure flow error handling."""
mock_config_entry.add_to_hass(hass)
mock_saunum_client.connect.side_effect = side_effect
result = await mock_config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
mock_saunum_client_class.create.side_effect = side_effect
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
TEST_RECONFIGURE_INPUT,
@@ -161,8 +160,8 @@ async def test_reconfigure_errors(
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": error_base}
# Test recovery - clear the error and try again
mock_saunum_client.connect.side_effect = None
# Test recovery - try again without the error
mock_saunum_client_class.create.side_effect = None
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
+7 -3
View File
@@ -1,5 +1,7 @@
"""Test Saunum Leil integration setup and teardown."""
from unittest.mock import patch
from pysaunum import SaunumConnectionError
import pytest
from syrupy.assertion import SnapshotAssertion
@@ -35,9 +37,11 @@ async def test_async_setup_entry_connection_failed(
"""Test integration setup fails when connection cannot be established."""
mock_config_entry.add_to_hass(hass)
mock_saunum_client.connect.side_effect = SaunumConnectionError("Connection failed")
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
with patch(
"homeassistant.components.saunum.SaunumClient.create",
side_effect=SaunumConnectionError("Connection failed"),
):
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY