core/tests/components/homeassistant/test_repairs.py

136 lines
4.8 KiB
Python

"""Test the Homeassistant repairs module."""
from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator, WebSocketGenerator
async def test_integration_not_found_confirm_step(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test the integration_not_found issue confirm step."""
assert await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {})
await hass.async_block_till_done()
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
await hass.async_block_till_done()
MockConfigEntry(domain="test1").add_to_hass(hass)
assert await async_setup_component(hass, "test1", {}) is False
await hass.async_block_till_done()
entry1 = MockConfigEntry(domain="test1")
entry1.add_to_hass(hass)
entry2 = MockConfigEntry(domain="test1")
entry2.add_to_hass(hass)
issue_id = "integration_not_found.test1"
await async_process_repairs_platforms(hass)
ws_client = await hass_ws_client(hass)
http_client = await hass_client()
# Assert the issue is present
await ws_client.send_json({"id": 1, "type": "repairs/list_issues"})
msg = await ws_client.receive_json()
assert msg["success"]
assert len(msg["result"]["issues"]) == 1
issue = msg["result"]["issues"][0]
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"domain": "test1"}
data = await start_repair_fix_flow(http_client, HOMEASSISTANT_DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "init"
assert data["description_placeholders"] == {"domain": "test1"}
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "menu"
# Apply fix
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "confirm"}
)
assert data["type"] == "create_entry"
await hass.async_block_till_done()
assert hass.config_entries.async_get_entry(entry1.entry_id) is None
assert hass.config_entries.async_get_entry(entry2.entry_id) is None
# Assert the issue is resolved
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
msg = await ws_client.receive_json()
assert msg["success"]
assert len(msg["result"]["issues"]) == 0
async def test_integration_not_found_ignore_step(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test the integration_not_found issue ignore step."""
assert await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {})
await hass.async_block_till_done()
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
await hass.async_block_till_done()
MockConfigEntry(domain="test1").add_to_hass(hass)
assert await async_setup_component(hass, "test1", {}) is False
await hass.async_block_till_done()
entry1 = MockConfigEntry(domain="test1")
entry1.add_to_hass(hass)
issue_id = "integration_not_found.test1"
await async_process_repairs_platforms(hass)
ws_client = await hass_ws_client(hass)
http_client = await hass_client()
# Assert the issue is present
await ws_client.send_json({"id": 1, "type": "repairs/list_issues"})
msg = await ws_client.receive_json()
assert msg["success"]
assert len(msg["result"]["issues"]) == 1
issue = msg["result"]["issues"][0]
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"domain": "test1"}
data = await start_repair_fix_flow(http_client, HOMEASSISTANT_DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "init"
assert data["description_placeholders"] == {"domain": "test1"}
# Show menu
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "menu"
# Apply fix
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "ignore"}
)
assert data["type"] == "abort"
assert data["reason"] == "issue_ignored"
await hass.async_block_till_done()
assert hass.config_entries.async_get_entry(entry1.entry_id)
# Assert the issue is resolved
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
msg = await ws_client.receive_json()
assert msg["success"]
assert len(msg["result"]["issues"]) == 1
assert msg["result"]["issues"][0].get("dismissed_version") is not None