mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 11:08:17 +00:00
Fix tests for smarla config_flow
This commit is contained in:
parent
73d37972df
commit
2bdcdaf446
@ -1,6 +1,5 @@
|
|||||||
"""Test config flow for Swing2Sleep Smarla integration."""
|
"""Test config flow for Swing2Sleep Smarla integration."""
|
||||||
|
|
||||||
import json
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -13,11 +12,7 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
MOCK_ACCESS_TOKEN = "eyJyZWZyZXNoVG9rZW4iOiJ0ZXN0IiwiYXBwSWRlbnRpZmllciI6IkhBLXRlc3QiLCJzZXJpYWxOdW1iZXIiOiJBQkNEIn0="
|
MOCK_ACCESS_TOKEN = "eyJyZWZyZXNoVG9rZW4iOiJ0ZXN0IiwiYXBwSWRlbnRpZmllciI6IkhBLXRlc3QiLCJzZXJpYWxOdW1iZXIiOiJBQkNEIn0="
|
||||||
MOCK_ACCESS_TOKEN_JSON = {
|
MOCK_SERIAL_NUMBER = "ABCD"
|
||||||
"refreshToken": "test",
|
|
||||||
"appIdentifier": "HA-test",
|
|
||||||
"serialNumber": "ABCD",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_show_form(hass: HomeAssistant) -> None:
|
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:
|
async def test_create_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test creating a config entry."""
|
"""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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER},
|
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["type"] == FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == MOCK_ACCESS_TOKEN_JSON["serialNumber"]
|
assert result["title"] == MOCK_SERIAL_NUMBER
|
||||||
assert result["data"] == {CONF_ACCESS_TOKEN: json.dumps(MOCK_ACCESS_TOKEN_JSON)}
|
assert result["data"] == {CONF_ACCESS_TOKEN: MOCK_ACCESS_TOKEN}
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_auth(hass: HomeAssistant) -> None:
|
async def test_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
"""Test we show user form on invalid auth."""
|
"""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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER},
|
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."""
|
"""Test we abort config flow if Smarla device already configured."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id=MOCK_ACCESS_TOKEN_JSON["serialNumber"],
|
unique_id=MOCK_SERIAL_NUMBER,
|
||||||
source=config_entries.SOURCE_USER,
|
source=config_entries.SOURCE_USER,
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER},
|
context={"source": config_entries.SOURCE_USER},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user