2019-05-09 16:11:51 +00:00
|
|
|
"""Define tests for the IQVIA config flow."""
|
2024-03-08 13:50:04 +00:00
|
|
|
|
2020-08-03 17:35:36 +00:00
|
|
|
from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN
|
|
|
|
from homeassistant.config_entries import SOURCE_USER
|
2023-02-08 17:12:56 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2024-04-02 21:01:37 +00:00
|
|
|
from homeassistant.data_entry_flow import FlowResultType
|
2019-05-09 16:11:51 +00:00
|
|
|
|
|
|
|
|
2023-02-13 12:03:51 +00:00
|
|
|
async def test_duplicate_error(hass: HomeAssistant, config, config_entry) -> None:
|
2019-05-09 16:11:51 +00:00
|
|
|
"""Test that errors are shown when duplicates are added."""
|
2020-08-03 17:35:36 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
2022-01-21 04:45:32 +00:00
|
|
|
DOMAIN, context={"source": SOURCE_USER}, data=config
|
2020-08-03 17:35:36 +00:00
|
|
|
)
|
2024-04-02 21:01:37 +00:00
|
|
|
assert result["type"] is FlowResultType.ABORT
|
2020-08-03 17:35:36 +00:00
|
|
|
assert result["reason"] == "already_configured"
|
2019-05-09 16:11:51 +00:00
|
|
|
|
|
|
|
|
2023-02-08 17:12:56 +00:00
|
|
|
async def test_invalid_zip_code(hass: HomeAssistant) -> None:
|
2019-05-09 16:11:51 +00:00
|
|
|
"""Test that an invalid ZIP code key throws an error."""
|
2020-08-03 17:35:36 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
2022-01-21 04:45:32 +00:00
|
|
|
DOMAIN, context={"source": SOURCE_USER}, data={CONF_ZIP_CODE: "bad"}
|
2020-08-03 17:35:36 +00:00
|
|
|
)
|
2024-04-02 21:01:37 +00:00
|
|
|
assert result["type"] is FlowResultType.FORM
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["errors"] == {CONF_ZIP_CODE: "invalid_zip_code"}
|
2019-05-09 16:11:51 +00:00
|
|
|
|
|
|
|
|
2023-02-08 17:12:56 +00:00
|
|
|
async def test_show_form(hass: HomeAssistant) -> None:
|
2019-05-09 16:11:51 +00:00
|
|
|
"""Test that the form is served with no input."""
|
2020-08-03 17:35:36 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
2024-04-02 21:01:37 +00:00
|
|
|
assert result["type"] is FlowResultType.FORM
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["step_id"] == "user"
|
2019-05-09 16:11:51 +00:00
|
|
|
|
|
|
|
|
2023-02-13 12:03:51 +00:00
|
|
|
async def test_step_user(hass: HomeAssistant, config, setup_iqvia) -> None:
|
2020-08-03 17:35:36 +00:00
|
|
|
"""Test that the user step works (without MFA)."""
|
2022-01-21 04:45:32 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}, data=config
|
|
|
|
)
|
2024-04-02 21:01:37 +00:00
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
2022-01-21 04:45:32 +00:00
|
|
|
assert result["title"] == "12345"
|
|
|
|
assert result["data"] == {CONF_ZIP_CODE: "12345"}
|