mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Split simple and recovery in onewire config-flow user tests (#135102)
This commit is contained in:
parent
f05e234c30
commit
d46be61b6f
@ -11,7 +11,6 @@ rules:
|
|||||||
status: todo
|
status: todo
|
||||||
comment: >
|
comment: >
|
||||||
Let's have test_user_options_empty_selection end in CREATE_ENTRY
|
Let's have test_user_options_empty_selection end in CREATE_ENTRY
|
||||||
Split the happy flow and the not happy flow in test_user_flow
|
|
||||||
runtime-data: done
|
runtime-data: done
|
||||||
test-before-setup: done
|
test-before-setup: done
|
||||||
appropriate-polling: done
|
appropriate-polling: done
|
||||||
|
@ -39,13 +39,31 @@ async def filled_device_registry(
|
|||||||
return device_registry
|
return device_registry
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow."""
|
"""Test user flow."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
|
||||||
assert not result["errors"]
|
with patch(
|
||||||
|
"homeassistant.components.onewire.onewirehub.protocol.proxy",
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
new_entry = result["result"]
|
||||||
|
assert new_entry.title == "1.2.3.4"
|
||||||
|
assert new_entry.data == {CONF_HOST: "1.2.3.4", CONF_PORT: 1234}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_flow_recovery(hass: HomeAssistant) -> None:
|
||||||
|
"""Test user flow recovery after invalid server."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
|
)
|
||||||
|
|
||||||
# Invalid server
|
# Invalid server
|
||||||
with patch(
|
with patch(
|
||||||
@ -57,9 +75,9 @@ async def test_user_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
|
|||||||
user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
|
user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {"base": "cannot_connect"}
|
assert result["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
# Valid server
|
# Valid server
|
||||||
with patch(
|
with patch(
|
||||||
@ -70,19 +88,14 @@ async def test_user_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
|
|||||||
user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
|
user_input={CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "1.2.3.4"
|
new_entry = result["result"]
|
||||||
assert result["data"] == {
|
assert new_entry.title == "1.2.3.4"
|
||||||
CONF_HOST: "1.2.3.4",
|
assert new_entry.data == {CONF_HOST: "1.2.3.4", CONF_PORT: 1234}
|
||||||
CONF_PORT: 1234,
|
|
||||||
}
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_duplicate(
|
async def test_user_duplicate(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry, mock_setup_entry: AsyncMock
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test user duplicate flow."""
|
"""Test user duplicate flow."""
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user