From 2bdcdaf446cc7824a24e0de99631b1a878f48bb3 Mon Sep 17 00:00:00 2001 From: Robin Lintermann Date: Tue, 6 May 2025 09:34:53 +0000 Subject: [PATCH] Fix tests for smarla config_flow --- tests/components/smarla/test_config_flow.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/components/smarla/test_config_flow.py b/tests/components/smarla/test_config_flow.py index 893e5058aa1..eff708aeaa8 100644 --- a/tests/components/smarla/test_config_flow.py +++ b/tests/components/smarla/test_config_flow.py @@ -1,6 +1,5 @@ """Test config flow for Swing2Sleep Smarla integration.""" -import json from unittest.mock import AsyncMock, patch from homeassistant import config_entries @@ -13,11 +12,7 @@ from homeassistant.data_entry_flow import FlowResultType from tests.common import MockConfigEntry MOCK_ACCESS_TOKEN = "eyJyZWZyZXNoVG9rZW4iOiJ0ZXN0IiwiYXBwSWRlbnRpZmllciI6IkhBLXRlc3QiLCJzZXJpYWxOdW1iZXIiOiJBQkNEIn0=" -MOCK_ACCESS_TOKEN_JSON = { - "refreshToken": "test", - "appIdentifier": "HA-test", - "serialNumber": "ABCD", -} +MOCK_SERIAL_NUMBER = "ABCD" async def test_show_form(hass: HomeAssistant) -> None: @@ -32,7 +27,7 @@ async def test_show_form(hass: HomeAssistant) -> None: async def test_create_entry(hass: HomeAssistant) -> None: """Test creating a config entry.""" - with patch.object(Connection, "get_token", new=AsyncMock(return_value=True)): + with patch.object(Connection, "refresh_token", new=AsyncMock(return_value=True)): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, @@ -40,13 +35,13 @@ async def test_create_entry(hass: HomeAssistant) -> None: ) assert result["type"] == FlowResultType.CREATE_ENTRY - assert result["title"] == MOCK_ACCESS_TOKEN_JSON["serialNumber"] - assert result["data"] == {CONF_ACCESS_TOKEN: json.dumps(MOCK_ACCESS_TOKEN_JSON)} + assert result["title"] == MOCK_SERIAL_NUMBER + assert result["data"] == {CONF_ACCESS_TOKEN: MOCK_ACCESS_TOKEN} async def test_invalid_auth(hass: HomeAssistant) -> None: """Test we show user form on invalid auth.""" - with patch.object(Connection, "get_token", new=AsyncMock(return_value=None)): + with patch.object(Connection, "refresh_token", new=AsyncMock(return_value=None)): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, @@ -73,12 +68,12 @@ async def test_device_exists_abort(hass: HomeAssistant) -> None: """Test we abort config flow if Smarla device already configured.""" config_entry = MockConfigEntry( domain=DOMAIN, - unique_id=MOCK_ACCESS_TOKEN_JSON["serialNumber"], + unique_id=MOCK_SERIAL_NUMBER, source=config_entries.SOURCE_USER, ) config_entry.add_to_hass(hass) - with patch.object(Connection, "get_token", new=AsyncMock(return_value=True)): + with patch.object(Connection, "refresh_token", new=AsyncMock(return_value=True)): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER},