コード例 #1
0
async def test_options_flow_cannot_connect(hass):
    """Test that options flow works."""

    config_entry = MockConfigEntry(
        version=1,
        domain=DOMAIN,
        title="Wartenau",
        data=FIXTURE_CONFIG_ENTRY,
        source="user",
        connection_class=CONN_CLASS_CLOUD_POLL,
        system_options={"disable_new_entities": False},
        options=FIXTURE_OPTIONS,
        unique_id="1234",
    )
    config_entry.add_to_hass(hass)

    with patch(
        "pygti.gti.GTI.departureList",
        side_effect=CannotConnect(),
    ):
        assert await hass.config_entries.async_setup(config_entry.entry_id)

        result = await hass.config_entries.options.async_init(config_entry.entry_id)

        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["step_id"] == "init"

        assert result["errors"] == {"base": "cannot_connect"}
コード例 #2
0
async def test_options_flow_cannot_connect(hass):
    """Test that options flow works."""

    config_entry = MockConfigEntry(
        version=1,
        domain=DOMAIN,
        title="Wartenau",
        data=FIXTURE_CONFIG_ENTRY,
        source=SOURCE_USER,
        connection_class=CONN_CLASS_CLOUD_POLL,
        system_options={"disable_new_entities": False},
        options=FIXTURE_OPTIONS,
        unique_id="1234",
    )
    config_entry.add_to_hass(hass)

    with patch("homeassistant.components.hvv_departures.PLATFORMS", new=[]), patch(
        "homeassistant.components.hvv_departures.hub.GTI.init", return_value=True
    ), patch(
        "homeassistant.components.hvv_departures.hub.GTI.departureList",
        return_value=FIXTURE_DEPARTURE_LIST,
    ):
        assert await hass.config_entries.async_setup(config_entry.entry_id)
        await hass.async_block_till_done()

    with patch(
        "homeassistant.components.hvv_departures.hub.GTI.departureList",
        side_effect=CannotConnect(),
    ):
        result = await hass.config_entries.options.async_init(config_entry.entry_id)

        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["step_id"] == "init"

        assert result["errors"] == {"base": "cannot_connect"}
コード例 #3
0
async def test_user_flow_cannot_connect(hass):
    """Test that config flow handles connection errors."""

    with patch(
            "homeassistant.components.hvv_departures.hub.GTI.init",
            side_effect=CannotConnect(),
    ):

        # step: user
        result_user = await hass.config_entries.flow.async_init(
            DOMAIN,
            context={"source": SOURCE_USER},
            data={
                CONF_HOST: "api-test.geofox.de",
                CONF_USERNAME: "******",
                CONF_PASSWORD: "******",
            },
        )

        assert result_user["type"] == "form"
        assert result_user["errors"] == {"base": "cannot_connect"}