mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +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
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
|
||||||
from twentemilieu import TwenteMilieuAddressError, TwenteMilieuConnectionError
|
from twentemilieu import TwenteMilieuAddressError, TwenteMilieuConnectionError
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -15,6 +14,7 @@ from homeassistant.components.twentemilieu.const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
|
from homeassistant.const import CONF_ID
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
@ -24,16 +24,16 @@ pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
@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."""
|
"""Test registering an integration and finishing flow works."""
|
||||||
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.get("type") is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result.get("step_id") == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={
|
user_input={
|
||||||
CONF_POST_CODE: "1234AB",
|
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 result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result2 == snapshot
|
|
||||||
|
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(
|
async def test_invalid_address(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_twentemilieu: MagicMock,
|
mock_twentemilieu: MagicMock,
|
||||||
snapshot: SnapshotAssertion,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test full user flow when the user enters an incorrect address.
|
"""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}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result.get("step_id") == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
mock_twentemilieu.unique_id.side_effect = TwenteMilieuAddressError
|
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"],
|
result["flow_id"],
|
||||||
user_input={
|
user_input={
|
||||||
CONF_POST_CODE: "1234",
|
CONF_POST_CODE: "1234",
|
||||||
@ -72,12 +80,12 @@ async def test_invalid_address(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2.get("type") is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result2.get("step_id") == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result2.get("errors") == {"base": "invalid_address"}
|
assert result["errors"] == {"base": "invalid_address"}
|
||||||
|
|
||||||
mock_twentemilieu.unique_id.side_effect = None
|
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"],
|
result["flow_id"],
|
||||||
user_input={
|
user_input={
|
||||||
CONF_POST_CODE: "1234AB",
|
CONF_POST_CODE: "1234AB",
|
||||||
@ -85,8 +93,17 @@ async def test_invalid_address(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result3.get("type") is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result3 == snapshot
|
|
||||||
|
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(
|
async def test_connection_error(
|
||||||
@ -106,9 +123,33 @@ async def test_connection_error(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result.get("step_id") == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result.get("errors") == {"base": "cannot_connect"}
|
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")
|
@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["type"] is FlowResultType.ABORT
|
||||||
assert result.get("reason") == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user