mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Update test_config_flow for solarlog (#132104)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
14897f921c
commit
5ae875be77
@ -9,7 +9,6 @@ from solarlog_cli.solarlog_exceptions import (
|
|||||||
SolarLogError,
|
SolarLogError,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.solarlog import config_flow
|
|
||||||
from homeassistant.components.solarlog.const import CONF_HAS_PWD, DOMAIN
|
from homeassistant.components.solarlog.const import CONF_HAS_PWD, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
@ -35,7 +34,6 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: HOST, CONF_HAS_PWD: False},
|
{CONF_HOST: HOST, CONF_HAS_PWD: False},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result2["title"] == HOST
|
assert result2["title"] == HOST
|
||||||
@ -44,13 +42,6 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
def init_config_flow(hass: HomeAssistant) -> config_flow.SolarLogConfigFlow:
|
|
||||||
"""Init a configuration flow."""
|
|
||||||
flow = config_flow.SolarLogConfigFlow()
|
|
||||||
flow.hass = hass
|
|
||||||
return flow
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("test_connect")
|
@pytest.mark.usefixtures("test_connect")
|
||||||
async def test_user(
|
async def test_user(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -68,7 +59,6 @@ async def test_user(
|
|||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], {CONF_HOST: HOST, CONF_HAS_PWD: False}
|
result["flow_id"], {CONF_HOST: HOST, CONF_HAS_PWD: False}
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == HOST
|
assert result["title"] == HOST
|
||||||
@ -97,17 +87,19 @@ async def test_form_exceptions(
|
|||||||
mock_solarlog_connector: AsyncMock,
|
mock_solarlog_connector: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can handle Form exceptions."""
|
"""Test we can handle Form exceptions."""
|
||||||
flow = init_config_flow(hass)
|
|
||||||
|
|
||||||
result = await flow.async_step_user()
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["errors"] == {}
|
||||||
|
|
||||||
mock_solarlog_connector.test_connection.side_effect = exception1
|
mock_solarlog_connector.test_connection.side_effect = exception1
|
||||||
|
|
||||||
# tests with connection error
|
# tests with connection error
|
||||||
result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: False})
|
result = await hass.config_entries.flow.async_configure(
|
||||||
await hass.async_block_till_done()
|
result["flow_id"], user_input={CONF_HOST: HOST, CONF_HAS_PWD: False}
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
@ -117,14 +109,16 @@ async def test_form_exceptions(
|
|||||||
mock_solarlog_connector.test_connection.side_effect = None
|
mock_solarlog_connector.test_connection.side_effect = None
|
||||||
mock_solarlog_connector.test_extended_data_available.side_effect = exception2
|
mock_solarlog_connector.test_extended_data_available.side_effect = exception2
|
||||||
|
|
||||||
result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: True})
|
result = await hass.config_entries.flow.async_configure(
|
||||||
await hass.async_block_till_done()
|
result["flow_id"], user_input={CONF_HOST: HOST, CONF_HAS_PWD: True}
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "password"
|
assert result["step_id"] == "password"
|
||||||
|
|
||||||
result = await flow.async_step_password({CONF_PASSWORD: "pwd"})
|
result = await hass.config_entries.flow.async_configure(
|
||||||
await hass.async_block_till_done()
|
result["flow_id"], user_input={CONF_PASSWORD: "pwd"}
|
||||||
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "password"
|
assert result["step_id"] == "password"
|
||||||
@ -132,18 +126,10 @@ async def test_form_exceptions(
|
|||||||
|
|
||||||
mock_solarlog_connector.test_extended_data_available.side_effect = None
|
mock_solarlog_connector.test_extended_data_available.side_effect = None
|
||||||
|
|
||||||
# tests with all provided (no password)
|
# tests with all provided
|
||||||
result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: False})
|
result = await hass.config_entries.flow.async_configure(
|
||||||
await hass.async_block_till_done()
|
result["flow_id"], user_input={CONF_PASSWORD: "pwd"}
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == HOST
|
|
||||||
assert result["data"][CONF_HOST] == HOST
|
|
||||||
assert result["data"][CONF_HAS_PWD] is False
|
|
||||||
|
|
||||||
# tests with all provided (password)
|
|
||||||
result = await flow.async_step_password({CONF_PASSWORD: "pwd"})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == HOST
|
assert result["title"] == HOST
|
||||||
@ -205,7 +191,6 @@ async def test_reconfigure_flow(
|
|||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], {CONF_HAS_PWD: True, CONF_PASSWORD: password}
|
result["flow_id"], {CONF_HAS_PWD: True, CONF_PASSWORD: password}
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reconfigure_successful"
|
assert result["reason"] == "reconfigure_successful"
|
||||||
@ -257,7 +242,6 @@ async def test_reauth(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_PASSWORD: "other_pwd"},
|
{CONF_PASSWORD: "other_pwd"},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
@ -270,7 +254,6 @@ async def test_reauth(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_PASSWORD: "other_pwd"},
|
{CONF_PASSWORD: "other_pwd"},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user