mirror of
https://github.com/home-assistant/core.git
synced 2026-07-04 23:51:32 +02:00
Improve Android TV Remote tests by testing we can recover from errors (#151752)
This commit is contained in:
@@ -102,6 +102,10 @@ async def test_user_flow_cannot_connect(
|
||||
assert not result["errors"]
|
||||
|
||||
host = "1.2.3.4"
|
||||
name = "My Android TV"
|
||||
mac = "1A:2B:3C:4D:5E:6F"
|
||||
unique_id = "1a:2b:3c:4d:5e:6f"
|
||||
pin = "123456"
|
||||
|
||||
mock_api.async_generate_cert_if_missing = AsyncMock(return_value=True)
|
||||
mock_api.async_get_name_and_mac = AsyncMock(side_effect=CannotConnect())
|
||||
@@ -119,9 +123,31 @@ async def test_user_flow_cannot_connect(
|
||||
mock_api.async_get_name_and_mac.assert_called()
|
||||
mock_api.async_start_pairing.assert_not_called()
|
||||
|
||||
# End in CREATE_ENTRY to test that its able to recover
|
||||
mock_api.async_get_name_and_mac = AsyncMock(return_value=(name, mac))
|
||||
mock_api.async_start_pairing = AsyncMock(return_value=None)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"host": host}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "pair"
|
||||
assert "pin" in result["data_schema"].schema
|
||||
assert not result["errors"]
|
||||
|
||||
mock_api.async_finish_pairing = AsyncMock(return_value=None)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"pin": pin}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == name
|
||||
assert result["data"] == {"host": host, "name": name, "mac": mac}
|
||||
assert result["context"]["unique_id"] == unique_id
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_unload_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_user_flow_pairing_invalid_auth(
|
||||
@@ -146,6 +172,7 @@ async def test_user_flow_pairing_invalid_auth(
|
||||
host = "1.2.3.4"
|
||||
name = "My Android TV"
|
||||
mac = "1A:2B:3C:4D:5E:6F"
|
||||
unique_id = "1a:2b:3c:4d:5e:6f"
|
||||
pin = "123456"
|
||||
|
||||
mock_api.async_get_name_and_mac = AsyncMock(return_value=(name, mac))
|
||||
@@ -164,7 +191,7 @@ async def test_user_flow_pairing_invalid_auth(
|
||||
mock_api.async_generate_cert_if_missing.assert_called()
|
||||
mock_api.async_start_pairing.assert_called()
|
||||
|
||||
mock_api.async_finish_pairing = AsyncMock(side_effect=InvalidAuth())
|
||||
mock_api.async_finish_pairing = AsyncMock(side_effect=[InvalidAuth(), None])
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"pin": pin}
|
||||
@@ -181,9 +208,19 @@ async def test_user_flow_pairing_invalid_auth(
|
||||
assert mock_api.async_start_pairing.call_count == 1
|
||||
assert mock_api.async_finish_pairing.call_count == 1
|
||||
|
||||
# End in CREATE_ENTRY to test that its able to recover
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"pin": pin}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == name
|
||||
assert result["data"] == {"host": host, "name": name, "mac": mac}
|
||||
assert result["context"]["unique_id"] == unique_id
|
||||
|
||||
assert mock_api.async_finish_pairing.call_count == 2
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_unload_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_user_flow_pairing_connection_closed(
|
||||
@@ -208,6 +245,7 @@ async def test_user_flow_pairing_connection_closed(
|
||||
host = "1.2.3.4"
|
||||
name = "My Android TV"
|
||||
mac = "1A:2B:3C:4D:5E:6F"
|
||||
unique_id = "1a:2b:3c:4d:5e:6f"
|
||||
pin = "123456"
|
||||
|
||||
mock_api.async_get_name_and_mac = AsyncMock(return_value=(name, mac))
|
||||
@@ -243,9 +281,19 @@ async def test_user_flow_pairing_connection_closed(
|
||||
assert mock_api.async_start_pairing.call_count == 2
|
||||
assert mock_api.async_finish_pairing.call_count == 1
|
||||
|
||||
# End in CREATE_ENTRY to test that its able to recover
|
||||
mock_api.async_finish_pairing = AsyncMock(return_value=None)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"pin": pin}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == name
|
||||
assert result["data"] == {"host": host, "name": name, "mac": mac}
|
||||
assert result["context"]["unique_id"] == unique_id
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_unload_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_user_flow_pairing_connection_closed_followed_by_cannot_connect(
|
||||
@@ -568,6 +616,7 @@ async def test_zeroconf_flow_pairing_invalid_auth(
|
||||
host = "1.2.3.4"
|
||||
name = "My Android TV"
|
||||
mac = "1A:2B:3C:4D:5E:6F"
|
||||
unique_id = "1a:2b:3c:4d:5e:6f"
|
||||
pin = "123456"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -602,7 +651,7 @@ async def test_zeroconf_flow_pairing_invalid_auth(
|
||||
mock_api.async_generate_cert_if_missing.assert_called()
|
||||
mock_api.async_start_pairing.assert_called()
|
||||
|
||||
mock_api.async_finish_pairing = AsyncMock(side_effect=InvalidAuth())
|
||||
mock_api.async_finish_pairing = AsyncMock(side_effect=[InvalidAuth(), None])
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"pin": pin}
|
||||
@@ -619,9 +668,18 @@ async def test_zeroconf_flow_pairing_invalid_auth(
|
||||
assert mock_api.async_start_pairing.call_count == 1
|
||||
assert mock_api.async_finish_pairing.call_count == 1
|
||||
|
||||
# End in CREATE_ENTRY to test that its able to recover
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"pin": pin}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == name
|
||||
assert result["data"] == {"host": host, "name": name, "mac": mac}
|
||||
assert result["context"]["unique_id"] == unique_id
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_unload_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_zeroconf_flow_already_configured_host_changed_reloads_entry(
|
||||
@@ -1123,7 +1181,12 @@ async def test_reconfigure_flow_cannot_connect(
|
||||
assert result["step_id"] == "reconfigure"
|
||||
|
||||
mock_api.async_generate_cert_if_missing = AsyncMock(return_value=True)
|
||||
mock_api.async_get_name_and_mac = AsyncMock(side_effect=CannotConnect())
|
||||
mock_api.async_get_name_and_mac = AsyncMock(
|
||||
side_effect=[
|
||||
CannotConnect(),
|
||||
(mock_config_entry.data["name"], mock_config_entry.data["mac"]),
|
||||
]
|
||||
)
|
||||
|
||||
new_host = "4.3.2.1"
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
@@ -1136,6 +1199,16 @@ async def test_reconfigure_flow_cannot_connect(
|
||||
assert mock_config_entry.data["host"] == "1.2.3.4"
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
# End in CREATE_ENTRY to test that its able to recover
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"host": new_host}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data["host"] == new_host
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_reconfigure_flow_unique_id_mismatch(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user