Improve airq test coverage (#90192)

* Add a missing test for aborting with "already_configured"

Test that config_flow aborts with "already_configured" when the
integration has already been configured

* Don't copy test data

Since #90232 is merged, it is no longer needed

* Split the initialisation into two steps, as it should be
pull/90413/head
Renat Sibgatulin 2023-03-28 12:59:03 +00:00 committed by GitHub
parent d228df6d81
commit 091932c3ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,8 @@ from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
TEST_USER_DATA = {
@ -91,3 +93,25 @@ async def test_form_invalid_input(hass: HomeAssistant) -> None:
assert result2["type"] == FlowResultType.FORM
assert result2["errors"] == {"base": "invalid_input"}
async def test_duplicate_error(hass: HomeAssistant) -> None:
"""Test that errors are shown when duplicates are added."""
MockConfigEntry(
data=TEST_USER_DATA,
domain=DOMAIN,
unique_id=TEST_DEVICE_INFO["id"],
).add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch("aioairq.AirQ.validate"), patch(
"aioairq.AirQ.fetch_device_info", return_value=TEST_DEVICE_INFO
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], TEST_USER_DATA
)
assert result2["type"] == FlowResultType.ABORT
assert result2["reason"] == "already_configured"