Add helper functions for repair tests (#125886)

* Expose repairs constants and function for other components

* Reorder

* Use helper methods

* Adjust core_files

* Improve

* Update test_migrate.py
This commit is contained in:
epenet 2024-09-14 03:31:44 +02:00 committed by GitHub
parent 3eed5de367
commit 6d212ea24e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 150 additions and 360 deletions

View file

@ -126,9 +126,11 @@ tests: &tests
- tests/*.py
- tests/auth/**
- tests/backports/**
- tests/components/diagnostics/**
- tests/components/history/**
- tests/components/logbook/**
- tests/components/recorder/**
- tests/components/repairs/**
- tests/components/sensor/**
- tests/hassfest/**
- tests/helpers/**

View file

@ -2,16 +2,7 @@
from __future__ import annotations
from http import HTTPStatus
from homeassistant.components.doorbird.const import DOMAIN
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
@ -20,6 +11,11 @@ from homeassistant.setup import async_setup_component
from . import mock_not_found_exception
from .conftest import DoorbirdMockerType
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator
@ -43,19 +39,13 @@ async def test_change_schedule_fails(
await async_process_repairs_platforms(hass)
client = await hass_client()
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, issue_id)
flow_id = data["flow_id"]
placeholders = data["description_placeholders"]
assert "404" in placeholders["error"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"

View file

@ -1,22 +1,19 @@
"""Test repairs for Ecobee integration."""
from http import HTTPStatus
from unittest.mock import MagicMock
from homeassistant.components.ecobee import DOMAIN
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from .common import setup_platform
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator
THERMOSTAT_ID = 0
@ -53,20 +50,14 @@ async def test_ecobee_notify_repair_flow(
)
assert len(issue_registry.issues) == 1
url = RepairsFlowIndexView.url
resp = await http_client.post(
url, json={"handler": "notify", "issue_id": f"migrate_notify_{DOMAIN}_{DOMAIN}"}
data = await start_repair_fix_flow(
http_client, "notify", f"migrate_notify_{DOMAIN}_{DOMAIN}"
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "create_entry"
# Test confirm step in repair flow
await hass.async_block_till_done()

View file

@ -1,19 +1,15 @@
"""Test the Homeassistant repairs module."""
from http import HTTPStatus
from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
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
@ -48,32 +44,20 @@ async def test_integration_not_found_confirm_step(
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"domain": "test1"}
url = RepairsFlowIndexView.url
resp = await http_client.post(
url, json={"handler": HOMEASSISTANT_DOMAIN, "issue_id": issue_id}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
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"}
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
# Show menu
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "menu"
# Apply fix
resp = await http_client.post(url, json={"next_step_id": "confirm"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "confirm"}
)
assert data["type"] == "create_entry"
@ -118,32 +102,21 @@ async def test_integration_not_found_ignore_step(
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"domain": "test1"}
url = RepairsFlowIndexView.url
resp = await http_client.post(
url, json={"handler": HOMEASSISTANT_DOMAIN, "issue_id": issue_id}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
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"}
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
# Show menu
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "menu"
# Apply fix
resp = await http_client.post(url, json={"next_step_id": "ignore"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "ignore"}
)
assert data["type"] == "abort"
assert data["reason"] == "issue_ignored"

View file

@ -1,20 +1,15 @@
"""Test repairs for KNX integration."""
from http import HTTPStatus
from homeassistant.components.knx.const import DOMAIN, KNX_ADDRESS
from homeassistant.components.knx.schema import NotifySchema
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.issue_registry as ir
from .conftest import KNXTestKit
from tests.components.repairs import process_repair_fix_flow, start_repair_fix_flow
from tests.typing import ClientSessionGenerator
@ -59,21 +54,14 @@ async def test_knx_notify_service_issue(
)
# Test confirm step in repair flow
resp = await http_client.post(
RepairsFlowIndexView.url,
json={"handler": "notify", "issue_id": f"migrate_notify_{DOMAIN}_notify"},
data = await start_repair_fix_flow(
http_client, "notify", f"migrate_notify_{DOMAIN}_notify"
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
resp = await http_client.post(
RepairsFlowResourceView.url.format(flow_id=flow_id),
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "create_entry"
# Assert the issue is no longer present

View file

@ -1,6 +1,5 @@
"""Test repairs for notify entity component."""
from http import HTTPStatus
from unittest.mock import AsyncMock
import pytest
@ -9,18 +8,16 @@ from homeassistant.components.notify import (
DOMAIN as NOTIFY_DOMAIN,
migrate_notify_issue,
)
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, MockModule, mock_integration
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator
THERMOSTAT_ID = 0
@ -66,20 +63,12 @@ async def test_notify_migration_repair_flow(
)
assert len(issue_registry.issues) == 1
url = RepairsFlowIndexView.url
resp = await http_client.post(
url, json={"handler": NOTIFY_DOMAIN, "issue_id": translation_key}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(http_client, NOTIFY_DOMAIN, translation_key)
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "create_entry"
# Test confirm step in repair flow
await hass.async_block_till_done()

View file

@ -1,5 +1,17 @@
"""Tests for the repairs integration."""
from http import HTTPStatus
from typing import Any
from aiohttp.test_utils import TestClient
from homeassistant.components.repairs.issue_handler import ( # noqa: F401
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
@ -27,3 +39,23 @@ async def get_repairs(
assert msg["result"]
return msg["result"]["issues"]
async def start_repair_fix_flow(
client: TestClient, handler: str, issue_id: int
) -> dict[str, Any]:
"""Start a flow from an issue."""
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": handler, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
return await resp.json()
async def process_repair_fix_flow(
client: TestClient, flow_id: int, json: dict[str, Any] | None = None
) -> dict[str, Any]:
"""Return the repairs list of issues."""
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json=json)
assert resp.status == HTTPStatus.OK
return await resp.json()

View file

@ -1,12 +1,10 @@
"""Tests for the seventeentrack repair flow."""
from http import HTTPStatus
from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN
from homeassistant.components.repairs.websocket_api import RepairsFlowIndexView
from homeassistant.components.seventeentrack import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
@ -16,6 +14,7 @@ from . import goto_future, init_integration
from .conftest import DEFAULT_SUMMARY_LENGTH, get_package
from tests.common import MockConfigEntry
from tests.components.repairs import process_repair_fix_flow, start_repair_fix_flow
from tests.typing import ClientSessionGenerator
@ -49,13 +48,7 @@ async def test_repair(
client = await hass_client()
resp = await client.post(
RepairsFlowIndexView.url,
json={"handler": DOMAIN, "issue_id": repair_issue.issue_id},
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, repair_issue.issue_id)
flow_id = data["flow_id"]
assert data == {
@ -70,9 +63,7 @@ async def test_repair(
"preview": None,
}
resp = await client.post(RepairsFlowIndexView.url + f"/{flow_id}")
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
flow_id = data["flow_id"]
assert data == {

View file

@ -1,16 +1,12 @@
"""Test loading of the Tibber config entry."""
from http import HTTPStatus
from unittest.mock import MagicMock
from homeassistant.components.recorder import Recorder
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from tests.components.repairs import process_repair_fix_flow, start_repair_fix_flow
from tests.typing import ClientSessionGenerator
@ -40,21 +36,15 @@ async def test_repair_flow(
)
assert len(issue_registry.issues) == 1
url = RepairsFlowIndexView.url
resp = await http_client.post(
url, json={"handler": "notify", "issue_id": f"migrate_notify_tibber_{service}"}
data = await start_repair_fix_flow(
http_client, "notify", f"migrate_notify_tibber_{service}"
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
# Simulate the users confirmed the repair flow
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "create_entry"
await hass.async_block_till_done()

View file

@ -7,9 +7,6 @@ from unittest.mock import patch
from uiprotect.data import Camera
from homeassistant.components.automation import DOMAIN as AUTOMATION_DOMAIN
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.script import DOMAIN as SCRIPT_DOMAIN
from homeassistant.components.unifiprotect.const import DOMAIN
from homeassistant.const import SERVICE_RELOAD, Platform
@ -19,6 +16,7 @@ from homeassistant.setup import async_setup_component
from .utils import MockUFPFixture, init_entry
from tests.components.repairs import async_process_repairs_platforms
from tests.typing import WebSocketGenerator

View file

@ -3,24 +3,21 @@
from __future__ import annotations
from copy import copy, deepcopy
from http import HTTPStatus
from unittest.mock import AsyncMock, Mock
from uiprotect.data import Camera, CloudAccount, ModelType, Version
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.components.unifiprotect.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.core import HomeAssistant
from .utils import MockUFPFixture, init_entry
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator, WebSocketGenerator
@ -52,12 +49,7 @@ async def test_ea_warning_ignore(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(
url, json={"handler": DOMAIN, "issue_id": "ea_channel_warning"}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "ea_channel_warning")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -66,10 +58,7 @@ async def test_ea_warning_ignore(
}
assert data["step_id"] == "start"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -78,10 +67,7 @@ async def test_ea_warning_ignore(
}
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
@ -114,12 +100,7 @@ async def test_ea_warning_fix(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(
url, json={"handler": DOMAIN, "issue_id": "ea_channel_warning"}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "ea_channel_warning")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -139,10 +120,7 @@ async def test_ea_warning_fix(
ufp.ws_msg(mock_msg)
await hass.async_block_till_done()
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
@ -176,18 +154,12 @@ async def test_cloud_user_fix(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "cloud_user"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "cloud_user")
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -228,26 +200,17 @@ async def test_rtsp_read_only_ignore(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "start"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
@ -287,18 +250,12 @@ async def test_rtsp_read_only_fix(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "start"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
@ -337,18 +294,12 @@ async def test_rtsp_writable_fix(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "start"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
@ -398,18 +349,12 @@ async def test_rtsp_writable_fix_when_not_setup(
await hass.config_entries.async_unload(ufp.entry.entry_id)
await hass.async_block_till_done()
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "start"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"

View file

@ -2,12 +2,6 @@
from __future__ import annotations
from http import HTTPStatus
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.components.workday.const import CONF_REMOVE_HOLIDAYS, DOMAIN
from homeassistant.const import CONF_COUNTRY
from homeassistant.core import HomeAssistant
@ -23,6 +17,7 @@ from . import (
)
from tests.common import ANY
from tests.components.repairs import process_repair_fix_flow, start_repair_fix_flow
from tests.typing import ClientSessionGenerator, WebSocketGenerator
@ -52,24 +47,15 @@ async def test_bad_country(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "bad_country"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "bad_country")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {"title": entry.title}
assert data["step_id"] == "country"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={"country": "DE"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={"country": "DE"})
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={"province": "HB"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={"province": "HB"})
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -114,24 +100,15 @@ async def test_bad_country_none(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "bad_country"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "bad_country")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {"title": entry.title}
assert data["step_id"] == "country"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={"country": "DE"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={"country": "DE"})
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={})
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -176,19 +153,13 @@ async def test_bad_country_no_province(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "bad_country"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "bad_country")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {"title": entry.title}
assert data["step_id"] == "country"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={"country": "SE"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={"country": "SE"})
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -233,10 +204,7 @@ async def test_bad_province(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "bad_province"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "bad_province")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -245,10 +213,7 @@ async def test_bad_province(
}
assert data["step_id"] == "province"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={"province": "BW"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={"province": "BW"})
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -293,10 +258,7 @@ async def test_bad_province_none(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "bad_province"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "bad_province")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -305,10 +267,7 @@ async def test_bad_province_none(
}
assert data["step_id"] == "province"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id, json={})
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -359,13 +318,9 @@ async def test_bad_named_holiday(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(
url,
json={"handler": DOMAIN, "issue_id": "bad_named_holiday-1-not_a_holiday"},
data = await start_repair_fix_flow(
client, DOMAIN, "bad_named_holiday-1-not_a_holiday"
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -375,23 +330,17 @@ async def test_bad_named_holiday(
}
assert data["step_id"] == "fix_remove_holiday"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(
url, json={"remove_holidays": ["Christmas", "Not exist 2"]}
data = await process_repair_fix_flow(
client, flow_id, json={"remove_holidays": ["Christmas", "Not exist 2"]}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert data["errors"] == {
CONF_REMOVE_HOLIDAYS: "remove_holiday_error",
}
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(
url, json={"remove_holidays": ["Christmas", "Thanksgiving"]}
data = await process_repair_fix_flow(
client, flow_id, json={"remove_holidays": ["Christmas", "Thanksgiving"]}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -442,13 +391,7 @@ async def test_bad_date_holiday(
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(
url,
json={"handler": DOMAIN, "issue_id": "bad_date_holiday-1-2024_02_05"},
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "bad_date_holiday-1-2024_02_05")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
@ -458,10 +401,9 @@ async def test_bad_date_holiday(
}
assert data["step_id"] == "fix_remove_holiday"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url, json={"remove_holidays": ["2024-02-06"]})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(
client, flow_id, json={"remove_holidays": ["2024-02-06"]}
)
assert data["type"] == "create_entry"
await hass.async_block_till_done()
@ -543,18 +485,12 @@ async def test_other_fixable_issues(
"ignored": False,
} in results
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "issue_1"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(client, DOMAIN, "issue_1")
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
await hass.async_block_till_done()

View file

@ -1,25 +1,22 @@
"""Test the Z-Wave JS repairs module."""
from copy import deepcopy
from http import HTTPStatus
from unittest.mock import patch
from zwave_js_server.event import Event
from zwave_js_server.model.node import Node
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
)
from homeassistant.components.repairs.websocket_api import (
RepairsFlowIndexView,
RepairsFlowResourceView,
)
from homeassistant.components.zwave_js import DOMAIN
from homeassistant.components.zwave_js.helpers import get_device_id
from homeassistant.core import HomeAssistant
import homeassistant.helpers.device_registry as dr
import homeassistant.helpers.issue_registry as ir
from tests.components.repairs import (
async_process_repairs_platforms,
process_repair_fix_flow,
start_repair_fix_flow,
)
from tests.typing import ClientSessionGenerator, WebSocketGenerator
@ -84,30 +81,21 @@ async def test_device_config_file_changed_confirm_step(
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"device_name": device.name}
url = RepairsFlowIndexView.url
resp = await http_client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(http_client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "init"
assert data["description_placeholders"] == {"device_name": device.name}
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
# Show menu
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "menu"
# Apply fix
resp = await http_client.post(url, json={"next_step_id": "confirm"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "confirm"}
)
assert data["type"] == "create_entry"
@ -159,30 +147,21 @@ async def test_device_config_file_changed_ignore_step(
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"device_name": device.name}
url = RepairsFlowIndexView.url
resp = await http_client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(http_client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "init"
assert data["description_placeholders"] == {"device_name": device.name}
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
# Show menu
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "menu"
# Ignore the issue
resp = await http_client.post(url, json={"next_step_id": "ignore"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "ignore"}
)
assert data["type"] == "abort"
assert data["reason"] == "issue_ignored"
@ -228,22 +207,13 @@ async def test_invalid_issue(
issue = msg["result"]["issues"][0]
assert issue["issue_id"] == "invalid_issue_id"
url = RepairsFlowIndexView.url
resp = await http_client.post(
url, json={"handler": DOMAIN, "issue_id": "invalid_issue_id"}
)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(http_client, DOMAIN, "invalid_issue_id")
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
# Apply fix
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await http_client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(http_client, flow_id)
assert data["type"] == "create_entry"
@ -278,10 +248,7 @@ async def test_abort_confirm(
await hass_ws_client(hass)
http_client = await hass_client()
url = RepairsFlowIndexView.url
resp = await http_client.post(url, json={"handler": DOMAIN, "issue_id": issue_id})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await start_repair_fix_flow(http_client, DOMAIN, issue_id)
flow_id = data["flow_id"]
assert data["step_id"] == "init"
@ -290,11 +257,9 @@ async def test_abort_confirm(
await hass.config_entries.async_unload(integration.entry_id)
# Apply fix
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await http_client.post(url, json={"next_step_id": "confirm"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
data = await process_repair_fix_flow(
http_client, flow_id, json={"next_step_id": "confirm"}
)
assert data["type"] == "abort"
assert data["reason"] == "cannot_connect"