Repository: home-assistant/core
File: tests/components/fritz/test_config_flow.py (Python)

Code before:

async def test_ssdp_exception(hass: HomeAssistant) -> None:
    """Test starting a flow from discovery but no device found."""
    with patch(
        "homeassistant.components.fritz.config_flow.FritzConnection",
        side_effect=FritzConnectionException,
    ):
        result = await hass.config_entries.flow.async_init(
            DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA
        )
        assert result["type"] is FlowResultType.FORM
        assert result["step_id"] == "confirm"

        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            user_input={
                CONF_USERNAME: "fake_user",
                CONF_PASSWORD: "fake_pass",
            },
        )

        assert result["type"] is FlowResultType.FORM
        assert result["step_id"] == "confirm"


async def test_options_flow(hass: HomeAssistant) -> None:
    """Test options flow."""

    mock_config = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
    mock_config.add_to_hass(hass)

    result = await hass.config_entries.options.async_init(mock_config.entry_id)
    result = await hass.config_entries.options.async_configure(
        result["flow_id"],
        user_input={
            CONF_CONSIDER_HOME: 37,
        },
    )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["data"] == {
        CONF_OLD_DISCOVERY: False,
        CONF_CONSIDER_HOME: 37,
        CONF_FEATURE_DEVICE_TRACKING: True,
    }


async def test_ssdp_ipv6_link_local(hass: HomeAssistant) -> None:
    """Test ignoring ipv6-link-local while ssdp discovery."""

    result = await hass.config_entries.flow.async_init(

Review comment (bug):
this prevents every now and then occurring error like:

 ```
ERROR:homeassistant.config_entries:Error setting up entry Mock Title for fritz
Traceback (most recent call last):
  File "/workspaces/homeassistant-core/homeassistant/config_entries.py", line 762, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/homeassistant-core/homeassistant/components/fritz/__init__.py", line 58, in async_setup_entry
    await avm_wrapper.async_setup(entry.options)
  File "/workspaces/homeassistant-core/homeassistant/components/fritz/coordinator.py", line 149, in async_setup
    await self.hass.async_add_executor_job(self.setup)
asyncio.exceptions.CancelledError: Home Assistant is stopping

[...]

FAILED tests/components/fritz/test_config_flow.py::test_options_flow - AssertionError: assert (False or False or '_run_safe_shutdown_loop' in 'SyncWorker_0')
 ```

Code after:

async def test_ssdp_exception(hass: HomeAssistant) -> None:
    """Test starting a flow from discovery but no device found."""
    with patch(
        "homeassistant.components.fritz.config_flow.FritzConnection",
        side_effect=FritzConnectionException,
    ):
        result = await hass.config_entries.flow.async_init(
            DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA
        )
        assert result["type"] is FlowResultType.FORM
        assert result["step_id"] == "confirm"

        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            user_input={
                CONF_USERNAME: "fake_user",
                CONF_PASSWORD: "fake_pass",
            },
        )

        assert result["type"] is FlowResultType.FORM
        assert result["step_id"] == "confirm"


async def test_options_flow(hass: HomeAssistant, fc_class_mock) -> None:
    """Test options flow."""

    mock_config = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
    mock_config.add_to_hass(hass)

    result = await hass.config_entries.options.async_init(mock_config.entry_id)
    result = await hass.config_entries.options.async_configure(
        result["flow_id"],
        user_input={
            CONF_CONSIDER_HOME: 37,
        },
    )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["data"] == {
        CONF_OLD_DISCOVERY: False,
        CONF_CONSIDER_HOME: 37,
        CONF_FEATURE_DEVICE_TRACKING: True,
    }


async def test_ssdp_ipv6_link_local(hass: HomeAssistant) -> None:
    """Test ignoring ipv6-link-local while ssdp discovery."""

    result = await hass.config_entries.flow.async_init(