mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 01:58:20 +00:00
Patch both connection objects
This commit is contained in:
parent
6bbd357547
commit
f0a3ecd27b
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user