Patch both connection objects

This commit is contained in:
Robin Lintermann 2025-05-15 14:32:21 +00:00
parent 6bbd357547
commit f0a3ecd27b
2 changed files with 15 additions and 9 deletions

View File

@ -27,11 +27,17 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture
def mock_cf_connection():
"""Patch config_flow Connection object."""
with patch(
"homeassistant.components.smarla.config_flow.Connection"
) as mock_connection:
def mock_connection():
"""Patch Connection object."""
with (
patch(
"homeassistant.components.smarla.config_flow.Connection"
) as mock_connection,
patch(
"homeassistant.components.smarla.Connection",
mock_connection,
),
):
connection = MagicMock()
connection.token = AuthToken.from_json(MOCK_ACCESS_TOKEN_JSON)
connection.refresh_token = AsyncMock(return_value=True)

View File

@ -14,7 +14,7 @@ from . import MOCK_SERIAL_NUMBER, MOCK_USER_INPUT
from tests.common import MockConfigEntry
async def test_config_flow(hass: HomeAssistant, mock_cf_connection) -> None:
async def test_config_flow(hass: HomeAssistant, mock_connection) -> None:
"""Test creating a config entry."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -34,7 +34,7 @@ async def test_config_flow(hass: HomeAssistant, mock_cf_connection) -> None:
@pytest.mark.parametrize("error", ["malformed_token", "invalid_auth"])
async def test_form_error(hass: HomeAssistant, error: str, mock_cf_connection) -> None:
async def test_form_error(hass: HomeAssistant, error: str, mock_connection) -> None:
"""Test we show user form on invalid auth."""
match error:
case "malformed_token":
@ -44,7 +44,7 @@ async def test_form_error(hass: HomeAssistant, error: str, mock_cf_connection) -
)
case "invalid_auth":
error_patch = patch.object(
mock_cf_connection,
mock_connection,
"refresh_token",
new=AsyncMock(return_value=False),
)
@ -68,7 +68,7 @@ async def test_form_error(hass: HomeAssistant, error: str, mock_cf_connection) -
async def test_device_exists_abort(
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_cf_connection
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_connection
) -> None:
"""Test we abort config flow if Smarla device already configured."""
mock_config_entry.add_to_hass(hass)