Fix repairs for remove dates in Workday (#109626)

This commit is contained in:
G Johansson 2024-02-04 15:15:17 -05:00 committed by GitHub
parent babfdaac54
commit bc45b31335
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 163 additions and 27 deletions

View file

@ -1,4 +1,5 @@
"""Tests the Home Assistant workday binary sensor."""
from __future__ import annotations
from typing import Any
@ -181,6 +182,16 @@ TEST_CONFIG_REMOVE_NAMED = {
"remove_holidays": ["Not a Holiday", "Christmas", "Thanksgiving"],
"language": "en_US",
}
TEST_CONFIG_REMOVE_DATE = {
"name": DEFAULT_NAME,
"country": "US",
"excludes": DEFAULT_EXCLUDES,
"days_offset": DEFAULT_OFFSET,
"workdays": DEFAULT_WORKDAYS,
"add_holidays": [],
"remove_holidays": ["2024-02-05", "2024-02-06"],
"language": "en_US",
}
TEST_CONFIG_TOMORROW = {
"name": DEFAULT_NAME,
"country": "DE",

View file

@ -1,4 +1,5 @@
"""Test repairs for unifiprotect."""
from __future__ import annotations
from http import HTTPStatus
@ -10,12 +11,13 @@ from homeassistant.components.repairs.websocket_api import (
from homeassistant.components.workday.const import CONF_REMOVE_HOLIDAYS, DOMAIN
from homeassistant.const import CONF_COUNTRY
from homeassistant.core import HomeAssistant
from homeassistant.helpers.issue_registry import async_create_issue
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component
from . import (
TEST_CONFIG_INCORRECT_COUNTRY,
TEST_CONFIG_INCORRECT_PROVINCE,
TEST_CONFIG_REMOVE_DATE,
TEST_CONFIG_REMOVE_NAMED,
init_integration,
)
@ -329,6 +331,7 @@ async def test_bad_named_holiday(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test fixing bad province selecting none."""
assert await async_setup_component(hass, "repairs", {})
@ -337,6 +340,11 @@ async def test_bad_named_holiday(
state = hass.states.get("binary_sensor.workday_sensor")
assert state
issues = issue_registry.issues.keys()
for issue in issues:
if issue[0] == DOMAIN:
assert issue[1].startswith("bad_named")
ws_client = await hass_ws_client(hass)
client = await hass_client()
@ -365,7 +373,7 @@ async def test_bad_named_holiday(
CONF_REMOVE_HOLIDAYS: "Not a Holiday",
"title": entry.title,
}
assert data["step_id"] == "named_holiday"
assert data["step_id"] == "fix_remove_holiday"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(
@ -402,6 +410,81 @@ async def test_bad_named_holiday(
assert not issue
async def test_bad_date_holiday(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test fixing bad province selecting none."""
assert await async_setup_component(hass, "repairs", {})
entry = await init_integration(hass, TEST_CONFIG_REMOVE_DATE)
state = hass.states.get("binary_sensor.workday_sensor")
assert state
issues = issue_registry.issues.keys()
for issue in issues:
if issue[0] == DOMAIN:
assert issue[1].startswith("bad_date")
ws_client = await hass_ws_client(hass)
client = await hass_client()
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"]) > 0
issue = None
for i in msg["result"]["issues"]:
if i["issue_id"] == "bad_date_holiday-1-2024_02_05":
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()
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
CONF_COUNTRY: "US",
CONF_REMOVE_HOLIDAYS: "2024-02-05",
"title": entry.title,
}
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()
assert data["type"] == "create_entry"
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.workday_sensor")
assert state
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
msg = await ws_client.receive_json()
assert msg["success"]
issue = None
for i in msg["result"]["issues"]:
if i["issue_id"] == "bad_date_holiday-1-2024_02_05":
issue = i
assert not issue
issue = None
for i in msg["result"]["issues"]:
if i["issue_id"] == "bad_date_holiday-1-2024_02_06":
issue = i
assert issue
async def test_other_fixable_issues(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
@ -428,7 +511,7 @@ async def test_other_fixable_issues(
"severity": "error",
"translation_key": "issue_1",
}
async_create_issue(
ir.async_create_issue(
hass,
issue["domain"],
issue["issue_id"],