From 091932c3acd984465d4f2a474b8943e649c8fbd1 Mon Sep 17 00:00:00 2001 From: Renat Sibgatulin Date: Tue, 28 Mar 2023 12:59:03 +0000 Subject: [PATCH] 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 --- tests/components/airq/test_config_flow.py | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/components/airq/test_config_flow.py b/tests/components/airq/test_config_flow.py index af71dc813e2..252c12f80fa 100644 --- a/tests/components/airq/test_config_flow.py +++ b/tests/components/airq/test_config_flow.py @@ -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"