mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Small test cleanups in Twente Milieu (#133028)
This commit is contained in:
parent
52491bb75e
commit
f2aaf2ac4a
@ -1,93 +0,0 @@
|
||||
# serializer version: 1
|
||||
# name: test_full_user_flow
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'source': 'user',
|
||||
'unique_id': '12345',
|
||||
}),
|
||||
'data': dict({
|
||||
'house_letter': 'A',
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'description': None,
|
||||
'description_placeholders': None,
|
||||
'flow_id': <ANY>,
|
||||
'handler': 'twentemilieu',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'result': ConfigEntrySnapshot({
|
||||
'data': dict({
|
||||
'house_letter': 'A',
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'twentemilieu',
|
||||
'entry_id': <ANY>,
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': '12345',
|
||||
'unique_id': '12345',
|
||||
'version': 1,
|
||||
}),
|
||||
'title': '12345',
|
||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
||||
# name: test_invalid_address
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'source': 'user',
|
||||
'unique_id': '12345',
|
||||
}),
|
||||
'data': dict({
|
||||
'house_letter': None,
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'description': None,
|
||||
'description_placeholders': None,
|
||||
'flow_id': <ANY>,
|
||||
'handler': 'twentemilieu',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'result': ConfigEntrySnapshot({
|
||||
'data': dict({
|
||||
'house_letter': None,
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'twentemilieu',
|
||||
'entry_id': <ANY>,
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': '12345',
|
||||
'unique_id': '12345',
|
||||
'version': 1,
|
||||
}),
|
||||
'title': '12345',
|
||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
@ -3,7 +3,6 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from twentemilieu import TwenteMilieuAddressError, TwenteMilieuConnectionError
|
||||
|
||||
from homeassistant import config_entries
|
||||
@ -15,6 +14,7 @@ from homeassistant.components.twentemilieu.const import (
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
@ -24,16 +24,16 @@ pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
||||
async def test_full_user_flow(hass: HomeAssistant, snapshot: SnapshotAssertion) -> None:
|
||||
async def test_full_user_flow(hass: HomeAssistant) -> None:
|
||||
"""Test registering an integration and finishing flow works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result.get("type") is FlowResultType.FORM
|
||||
assert result.get("step_id") == "user"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_POST_CODE: "1234AB",
|
||||
@ -42,14 +42,22 @@ async def test_full_user_flow(hass: HomeAssistant, snapshot: SnapshotAssertion)
|
||||
},
|
||||
)
|
||||
|
||||
assert result2.get("type") is FlowResultType.CREATE_ENTRY
|
||||
assert result2 == snapshot
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "12345"
|
||||
assert config_entry.data == {
|
||||
CONF_HOUSE_LETTER: "A",
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_ID: 12345,
|
||||
CONF_POST_CODE: "1234AB",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
async def test_invalid_address(
|
||||
hass: HomeAssistant,
|
||||
mock_twentemilieu: MagicMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test full user flow when the user enters an incorrect address.
|
||||
|
||||
@ -60,11 +68,11 @@ async def test_invalid_address(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result.get("type") is FlowResultType.FORM
|
||||
assert result.get("step_id") == "user"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
mock_twentemilieu.unique_id.side_effect = TwenteMilieuAddressError
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_POST_CODE: "1234",
|
||||
@ -72,12 +80,12 @@ async def test_invalid_address(
|
||||
},
|
||||
)
|
||||
|
||||
assert result2.get("type") is FlowResultType.FORM
|
||||
assert result2.get("step_id") == "user"
|
||||
assert result2.get("errors") == {"base": "invalid_address"}
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "invalid_address"}
|
||||
|
||||
mock_twentemilieu.unique_id.side_effect = None
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_POST_CODE: "1234AB",
|
||||
@ -85,8 +93,17 @@ async def test_invalid_address(
|
||||
},
|
||||
)
|
||||
|
||||
assert result3.get("type") is FlowResultType.CREATE_ENTRY
|
||||
assert result3 == snapshot
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "12345"
|
||||
assert config_entry.data == {
|
||||
CONF_HOUSE_LETTER: None,
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_ID: 12345,
|
||||
CONF_POST_CODE: "1234AB",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
async def test_connection_error(
|
||||
@ -106,9 +123,33 @@ async def test_connection_error(
|
||||
},
|
||||
)
|
||||
|
||||
assert result.get("type") is FlowResultType.FORM
|
||||
assert result.get("step_id") == "user"
|
||||
assert result.get("errors") == {"base": "cannot_connect"}
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
# Recover from error
|
||||
mock_twentemilieu.unique_id.side_effect = None
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_POST_CODE: "1234AB",
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_HOUSE_LETTER: "A",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "12345"
|
||||
assert config_entry.data == {
|
||||
CONF_HOUSE_LETTER: "A",
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_ID: 12345,
|
||||
CONF_POST_CODE: "1234AB",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
||||
@ -128,5 +169,5 @@ async def test_address_already_set_up(
|
||||
},
|
||||
)
|
||||
|
||||
assert result.get("type") is FlowResultType.ABORT
|
||||
assert result.get("reason") == "already_configured"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
Loading…
x
Reference in New Issue
Block a user