Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Oct 31, 2023
1 parent 1318100 commit 2e1e57d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
3 changes: 1 addition & 2 deletions homeassistant/components/workday/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ def validate_custom_dates(user_input: dict[str, Any]) -> None:

year: int = dt_util.now().year
if country := user_input.get(CONF_COUNTRY):
cls = country_holidays(country)
obj_holidays = country_holidays(
country=country,
subdiv=user_input.get(CONF_PROVINCE),
years=year,
language=cls.default_language,
language=user_input.get(CONF_LANGUAGE),
)
else:
obj_holidays = HolidayBase(years=year)
Expand Down
65 changes: 65 additions & 0 deletions tests/components/workday/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Test the Workday config flow."""
from __future__ import annotations

from datetime import datetime

from freezegun.api import FrozenDateTimeFactory
import pytest

from homeassistant import config_entries
Expand All @@ -19,6 +22,7 @@
from homeassistant.const import CONF_LANGUAGE, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.util.dt import UTC

from . import init_integration

Expand Down Expand Up @@ -49,6 +53,7 @@ async def test_form(hass: HomeAssistant) -> None:
CONF_WORKDAYS: DEFAULT_WORKDAYS,
CONF_ADD_HOLIDAYS: [],
CONF_REMOVE_HOLIDAYS: [],
CONF_LANGUAGE: "de",
},
)
await hass.async_block_till_done()
Expand Down Expand Up @@ -537,3 +542,63 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None:
"province": "BW",
"language": "de",
}


pytestmark = pytest.mark.usefixtures()


@pytest.mark.parametrize(
("language", "holiday"),
[
("de", "Weihnachtstag"),
("en_US", "Christmas"),
],
)
async def test_language(
hass: HomeAssistant, language: str, holiday: str, freezer: FrozenDateTimeFactory
) -> None:
"""Test we get the forms."""
freezer.move_to(datetime(2023, 12, 25, 12, tzinfo=UTC)) # Monday

result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == FlowResultType.FORM

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_NAME: "Workday Sensor",
CONF_COUNTRY: "DE",
},
)
await hass.async_block_till_done()
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{
CONF_EXCLUDES: DEFAULT_EXCLUDES,
CONF_OFFSET: DEFAULT_OFFSET,
CONF_WORKDAYS: DEFAULT_WORKDAYS,
CONF_ADD_HOLIDAYS: [],
CONF_REMOVE_HOLIDAYS: [holiday],
CONF_LANGUAGE: language,
},
)
await hass.async_block_till_done()

assert result3["type"] == FlowResultType.CREATE_ENTRY
assert result3["title"] == "Workday Sensor"
assert result3["options"] == {
"name": "Workday Sensor",
"country": "DE",
"excludes": ["sat", "sun", "holiday"],
"days_offset": 0,
"workdays": ["mon", "tue", "wed", "thu", "fri"],
"add_holidays": [],
"remove_holidays": [holiday],
"language": language,
}

state = hass.states.get("binary_sensor.workday_sensor")
assert state is not None
assert state.state == "on"

0 comments on commit 2e1e57d

Please sign in to comment.