mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Clean up Elgato config flow tests (#133045)
This commit is contained in:
parent
6005b6d01c
commit
bcaf1dc20b
@ -1,128 +0,0 @@
|
|||||||
# serializer version: 1
|
|
||||||
# name: test_full_user_flow_implementation
|
|
||||||
FlowResultSnapshot({
|
|
||||||
'context': dict({
|
|
||||||
'source': 'user',
|
|
||||||
'unique_id': 'CN11A1A00001',
|
|
||||||
}),
|
|
||||||
'data': dict({
|
|
||||||
'host': '127.0.0.1',
|
|
||||||
'mac': None,
|
|
||||||
}),
|
|
||||||
'description': None,
|
|
||||||
'description_placeholders': None,
|
|
||||||
'flow_id': <ANY>,
|
|
||||||
'handler': 'elgato',
|
|
||||||
'minor_version': 1,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'result': ConfigEntrySnapshot({
|
|
||||||
'data': dict({
|
|
||||||
'host': '127.0.0.1',
|
|
||||||
'mac': None,
|
|
||||||
}),
|
|
||||||
'disabled_by': None,
|
|
||||||
'discovery_keys': dict({
|
|
||||||
}),
|
|
||||||
'domain': 'elgato',
|
|
||||||
'entry_id': <ANY>,
|
|
||||||
'minor_version': 1,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'pref_disable_new_entities': False,
|
|
||||||
'pref_disable_polling': False,
|
|
||||||
'source': 'user',
|
|
||||||
'title': 'CN11A1A00001',
|
|
||||||
'unique_id': 'CN11A1A00001',
|
|
||||||
'version': 1,
|
|
||||||
}),
|
|
||||||
'title': 'CN11A1A00001',
|
|
||||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
|
||||||
'version': 1,
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_full_zeroconf_flow_implementation
|
|
||||||
FlowResultSnapshot({
|
|
||||||
'context': dict({
|
|
||||||
'confirm_only': True,
|
|
||||||
'source': 'zeroconf',
|
|
||||||
'unique_id': 'CN11A1A00001',
|
|
||||||
}),
|
|
||||||
'data': dict({
|
|
||||||
'host': '127.0.0.1',
|
|
||||||
'mac': 'AA:BB:CC:DD:EE:FF',
|
|
||||||
}),
|
|
||||||
'description': None,
|
|
||||||
'description_placeholders': None,
|
|
||||||
'flow_id': <ANY>,
|
|
||||||
'handler': 'elgato',
|
|
||||||
'minor_version': 1,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'result': ConfigEntrySnapshot({
|
|
||||||
'data': dict({
|
|
||||||
'host': '127.0.0.1',
|
|
||||||
'mac': 'AA:BB:CC:DD:EE:FF',
|
|
||||||
}),
|
|
||||||
'disabled_by': None,
|
|
||||||
'discovery_keys': dict({
|
|
||||||
}),
|
|
||||||
'domain': 'elgato',
|
|
||||||
'entry_id': <ANY>,
|
|
||||||
'minor_version': 1,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'pref_disable_new_entities': False,
|
|
||||||
'pref_disable_polling': False,
|
|
||||||
'source': 'zeroconf',
|
|
||||||
'title': 'CN11A1A00001',
|
|
||||||
'unique_id': 'CN11A1A00001',
|
|
||||||
'version': 1,
|
|
||||||
}),
|
|
||||||
'title': 'CN11A1A00001',
|
|
||||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
|
||||||
'version': 1,
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_zeroconf_during_onboarding
|
|
||||||
FlowResultSnapshot({
|
|
||||||
'context': dict({
|
|
||||||
'source': 'zeroconf',
|
|
||||||
'unique_id': 'CN11A1A00001',
|
|
||||||
}),
|
|
||||||
'data': dict({
|
|
||||||
'host': '127.0.0.1',
|
|
||||||
'mac': 'AA:BB:CC:DD:EE:FF',
|
|
||||||
}),
|
|
||||||
'description': None,
|
|
||||||
'description_placeholders': None,
|
|
||||||
'flow_id': <ANY>,
|
|
||||||
'handler': 'elgato',
|
|
||||||
'minor_version': 1,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'result': ConfigEntrySnapshot({
|
|
||||||
'data': dict({
|
|
||||||
'host': '127.0.0.1',
|
|
||||||
'mac': 'AA:BB:CC:DD:EE:FF',
|
|
||||||
}),
|
|
||||||
'disabled_by': None,
|
|
||||||
'discovery_keys': dict({
|
|
||||||
}),
|
|
||||||
'domain': 'elgato',
|
|
||||||
'entry_id': <ANY>,
|
|
||||||
'minor_version': 1,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'pref_disable_new_entities': False,
|
|
||||||
'pref_disable_polling': False,
|
|
||||||
'source': 'zeroconf',
|
|
||||||
'title': 'CN11A1A00001',
|
|
||||||
'unique_id': 'CN11A1A00001',
|
|
||||||
'version': 1,
|
|
||||||
}),
|
|
||||||
'title': 'CN11A1A00001',
|
|
||||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
|
||||||
'version': 1,
|
|
||||||
})
|
|
||||||
# ---
|
|
@ -5,12 +5,11 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
|
|
||||||
from elgato import ElgatoConnectionError
|
from elgato import ElgatoConnectionError
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
|
||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.elgato.const import DOMAIN
|
from homeassistant.components.elgato.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||||
from homeassistant.const import CONF_HOST, CONF_SOURCE
|
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_SOURCE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
@ -21,7 +20,6 @@ async def test_full_user_flow_implementation(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_elgato: MagicMock,
|
mock_elgato: MagicMock,
|
||||||
mock_setup_entry: AsyncMock,
|
mock_setup_entry: AsyncMock,
|
||||||
snapshot: SnapshotAssertion,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the full manual user flow from start to finish."""
|
"""Test the full manual user flow from start to finish."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -29,15 +27,22 @@ async def test_full_user_flow_implementation(
|
|||||||
context={"source": SOURCE_USER},
|
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"], user_input={CONF_HOST: "127.0.0.1"}
|
result["flow_id"], user_input={CONF_HOST: "127.0.0.1"}
|
||||||
)
|
)
|
||||||
|
|
||||||
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 == "CN11A1A00001"
|
||||||
|
assert config_entry.data == {
|
||||||
|
CONF_HOST: "127.0.0.1",
|
||||||
|
CONF_MAC: None,
|
||||||
|
}
|
||||||
|
assert not config_entry.options
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
assert len(mock_elgato.info.mock_calls) == 1
|
assert len(mock_elgato.info.mock_calls) == 1
|
||||||
@ -47,7 +52,6 @@ async def test_full_zeroconf_flow_implementation(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_elgato: MagicMock,
|
mock_elgato: MagicMock,
|
||||||
mock_setup_entry: AsyncMock,
|
mock_setup_entry: AsyncMock,
|
||||||
snapshot: SnapshotAssertion,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the zeroconf flow from start to finish."""
|
"""Test the zeroconf flow from start to finish."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -64,9 +68,9 @@ async def test_full_zeroconf_flow_implementation(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("description_placeholders") == {"serial_number": "CN11A1A00001"}
|
assert result["description_placeholders"] == {"serial_number": "CN11A1A00001"}
|
||||||
assert result.get("step_id") == "zeroconf_confirm"
|
assert result["step_id"] == "zeroconf_confirm"
|
||||||
assert result.get("type") is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
|
||||||
progress = hass.config_entries.flow.async_progress()
|
progress = hass.config_entries.flow.async_progress()
|
||||||
assert len(progress) == 1
|
assert len(progress) == 1
|
||||||
@ -74,12 +78,19 @@ async def test_full_zeroconf_flow_implementation(
|
|||||||
assert "context" in progress[0]
|
assert "context" in progress[0]
|
||||||
assert progress[0]["context"].get("confirm_only") is True
|
assert progress[0]["context"].get("confirm_only") is True
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
||||||
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 == "CN11A1A00001"
|
||||||
|
assert config_entry.data == {
|
||||||
|
CONF_HOST: "127.0.0.1",
|
||||||
|
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||||
|
}
|
||||||
|
assert not config_entry.options
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
assert len(mock_elgato.info.mock_calls) == 1
|
assert len(mock_elgato.info.mock_calls) == 1
|
||||||
@ -97,9 +108,28 @@ async def test_connection_error(
|
|||||||
data={CONF_HOST: "127.0.0.1"},
|
data={CONF_HOST: "127.0.0.1"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result.get("errors") == {"base": "cannot_connect"}
|
assert result["errors"] == {"base": "cannot_connect"}
|
||||||
assert result.get("step_id") == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
# Recover from error
|
||||||
|
mock_elgato.info.side_effect = None
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": SOURCE_USER},
|
||||||
|
data={CONF_HOST: "127.0.0.2"},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
|
||||||
|
config_entry = result["result"]
|
||||||
|
assert config_entry.unique_id == "CN11A1A00001"
|
||||||
|
assert config_entry.data == {
|
||||||
|
CONF_HOST: "127.0.0.2",
|
||||||
|
CONF_MAC: None,
|
||||||
|
}
|
||||||
|
assert not config_entry.options
|
||||||
|
|
||||||
|
|
||||||
async def test_zeroconf_connection_error(
|
async def test_zeroconf_connection_error(
|
||||||
@ -122,8 +152,8 @@ async def test_zeroconf_connection_error(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("reason") == "cannot_connect"
|
assert result["reason"] == "cannot_connect"
|
||||||
assert result.get("type") is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_elgato")
|
@pytest.mark.usefixtures("mock_elgato")
|
||||||
@ -138,8 +168,8 @@ async def test_user_device_exists_abort(
|
|||||||
data={CONF_HOST: "127.0.0.1"},
|
data={CONF_HOST: "127.0.0.1"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result.get("reason") == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_elgato")
|
@pytest.mark.usefixtures("mock_elgato")
|
||||||
@ -162,8 +192,8 @@ async def test_zeroconf_device_exists_abort(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result.get("reason") == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert entries[0].data[CONF_HOST] == "127.0.0.1"
|
assert entries[0].data[CONF_HOST] == "127.0.0.1"
|
||||||
@ -183,8 +213,8 @@ async def test_zeroconf_device_exists_abort(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result.get("reason") == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert entries[0].data[CONF_HOST] == "127.0.0.2"
|
assert entries[0].data[CONF_HOST] == "127.0.0.2"
|
||||||
@ -195,7 +225,6 @@ async def test_zeroconf_during_onboarding(
|
|||||||
mock_elgato: MagicMock,
|
mock_elgato: MagicMock,
|
||||||
mock_setup_entry: AsyncMock,
|
mock_setup_entry: AsyncMock,
|
||||||
mock_onboarding: MagicMock,
|
mock_onboarding: MagicMock,
|
||||||
snapshot: SnapshotAssertion,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the zeroconf creates an entry during onboarding."""
|
"""Test the zeroconf creates an entry during onboarding."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -212,8 +241,15 @@ async def test_zeroconf_during_onboarding(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result == snapshot
|
|
||||||
|
config_entry = result["result"]
|
||||||
|
assert config_entry.unique_id == "CN11A1A00001"
|
||||||
|
assert config_entry.data == {
|
||||||
|
CONF_HOST: "127.0.0.1",
|
||||||
|
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||||
|
}
|
||||||
|
assert not config_entry.options
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
assert len(mock_elgato.info.mock_calls) == 1
|
assert len(mock_elgato.info.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user