Fix test coverage in workday (#133616)

This commit is contained in:
G Johansson 2024-12-21 12:45:00 +01:00 committed by GitHub
parent 6b666b3a0f
commit 11efec49db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 4 deletions

View File

@ -94,7 +94,11 @@ def _get_obj_holidays(
language=language,
categories=set_categories,
)
if (supported_languages := obj_holidays.supported_languages) and language == "en":
if (
(supported_languages := obj_holidays.supported_languages)
and language
and language.startswith("en")
):
for lang in supported_languages:
if lang.startswith("en"):
obj_holidays = country_holidays(

View File

@ -136,7 +136,7 @@ def validate_custom_dates(user_input: dict[str, Any]) -> None:
year: int = dt_util.now().year
if country := user_input.get(CONF_COUNTRY):
language = user_input.get(CONF_LANGUAGE)
language: str | None = user_input.get(CONF_LANGUAGE)
province = user_input.get(CONF_PROVINCE)
obj_holidays = country_holidays(
country=country,
@ -145,8 +145,10 @@ def validate_custom_dates(user_input: dict[str, Any]) -> None:
language=language,
)
if (
supported_languages := obj_holidays.supported_languages
) and language == "en":
(supported_languages := obj_holidays.supported_languages)
and language
and language.startswith("en")
):
for lang in supported_languages:
if lang.startswith("en"):
obj_holidays = country_holidays(

View File

@ -653,3 +653,48 @@ async def test_form_with_categories(hass: HomeAssistant) -> None:
"language": "de",
"category": ["half_day"],
}
async def test_options_form_removes_subdiv(hass: HomeAssistant) -> None:
"""Test we get the form in options when removing a configured subdivision."""
entry = await init_integration(
hass,
{
"name": "Workday Sensor",
"country": "DE",
"excludes": ["sat", "sun", "holiday"],
"days_offset": 0,
"workdays": ["mon", "tue", "wed", "thu", "fri"],
"add_holidays": [],
"remove_holidays": [],
"language": "de",
"province": "BW",
},
)
result = await hass.config_entries.options.async_init(entry.entry_id)
result2 = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
"excludes": ["sat", "sun", "holiday"],
"days_offset": 0,
"workdays": ["mon", "tue", "wed", "thu", "fri"],
"add_holidays": [],
"remove_holidays": [],
"language": "de",
},
)
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["data"] == {
"name": "Workday Sensor",
"country": "DE",
"excludes": ["sat", "sun", "holiday"],
"days_offset": 0,
"workdays": ["mon", "tue", "wed", "thu", "fri"],
"add_holidays": [],
"remove_holidays": [],
"language": "de",
}