コード例 #1
0
async def test_user_flow_invalid_auth(hass):
    """Test that config flow handles invalid auth."""

    with patch(
            "homeassistant.components.hvv_departures.hub.GTI.init",
            side_effect=InvalidAuth(
                "ERROR_TEXT",
                "Bei der Verarbeitung der Anfrage ist ein technisches Problem aufgetreten.",
                "Authentication failed!",
            ),
    ):

        # 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": "invalid_auth"}
コード例 #2
0
async def test_options_flow_invalid_auth(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(
        "homeassistant.components.hvv_departures.hub.GTI.init",
        side_effect=InvalidAuth(
            "ERROR_TEXT",
            "Bei der Verarbeitung der Anfrage ist ein technisches Problem aufgetreten.",
            "Authentication failed!",
        ),
    ):
        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": "invalid_auth"}
コード例 #3
0
async def test_options_flow_invalid_auth(hass):
    """Test that options flow works."""

    config_entry = MockConfigEntry(
        version=1,
        domain=DOMAIN,
        title="Wartenau",
        data=FIXTURE_CONFIG_ENTRY,
        source=SOURCE_USER,
        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=InvalidAuth(
                "ERROR_TEXT",
                "Bei der Verarbeitung der Anfrage ist ein technisches Problem aufgetreten.",
                "Authentication failed!",
            ),
    ):
        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": "invalid_auth"}