Files
houseplan-card/tests_backend/test_ha_config_flow.py
T
Matysh 42c24abcb4 feat v1.12.0: Quality Scale conformance (phases 7-8)
- entry.runtime_data (HouseplanData in store.py) instead of hass.data; WS answers
  not_ready without a loaded entry
- test-before-setup (ConfigEntryNotReady), async_unload_entry, async_remove_entry
  (Lovelace resource cleanup), single_config_entry in manifest
- Store minor_version + migration hook; diagnostics.py (redacted); repairs
  (broken_plan issues, en/ru); system_health.py; strings.json
- quality_scale.yaml self-assessment; HA-harness tests (config flow, WS, upload)
  in CI on py3.13; CI backend job updated
2026-07-06 00:27:47 +03:00

51 lines
2.1 KiB
Python

"""Config flow tests (run in CI with pytest-homeassistant-custom-component)."""
from homeassistant import config_entries
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from custom_components.houseplan.const import CONF_ADMIN_ONLY, DOMAIN
async def test_user_flow_creates_entry(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_ADMIN_ONLY: True}
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "House Plan"
assert result["options"] == {CONF_ADMIN_ONLY: True}
async def test_single_instance(hass: HomeAssistant) -> None:
"""manifest single_config_entry must prevent a second entry."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
await hass.config_entries.flow.async_configure(result["flow_id"], user_input={})
result2 = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result2["type"] is FlowResultType.ABORT
assert result2["reason"] == "single_instance_allowed"
async def test_options_flow(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
result = await hass.config_entries.flow.async_configure(result["flow_id"], user_input={})
entry = hass.config_entries.async_entries(DOMAIN)[0]
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(entry.entry_id)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={CONF_ADMIN_ONLY: True}
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert entry.options == {CONF_ADMIN_ONLY: True}