Ejemplo n.º 1
0
async def test_abort_on_fetch_failed(hass, login, close_session):
    """Test when we have errors during fetch."""
    flow = init_config_flow(hass)

    with patch("pylinky.client.LinkyClient.fetch_data",
               side_effect=PyLinkyAccessException()):
        result = await flow.async_step_user({
            CONF_USERNAME: USERNAME,
            CONF_PASSWORD: PASSWORD
        })
        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["errors"] == {"base": "access"}

    with patch("pylinky.client.LinkyClient.fetch_data",
               side_effect=PyLinkyEnedisException()):
        result = await flow.async_step_user({
            CONF_USERNAME: USERNAME,
            CONF_PASSWORD: PASSWORD
        })
        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["errors"] == {"base": "enedis"}

    with patch("pylinky.client.LinkyClient.fetch_data",
               side_effect=PyLinkyException()):
        result = await flow.async_step_user({
            CONF_USERNAME: USERNAME,
            CONF_PASSWORD: PASSWORD
        })
        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["errors"] == {"base": "unknown"}
Ejemplo n.º 2
0
async def test_login_failed(hass: HomeAssistantType, login):
    """Test when we have errors during login."""
    login.return_value.login.side_effect = PyLinkyAccessException()
    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={"source": SOURCE_IMPORT},
        data={
            CONF_USERNAME: USERNAME,
            CONF_PASSWORD: PASSWORD
        },
    )
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["errors"] == {"base": "access"}
    hass.config_entries.flow.async_abort(result["flow_id"])

    login.return_value.login.side_effect = PyLinkyWrongLoginException()
    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={"source": SOURCE_USER},
        data={
            CONF_USERNAME: USERNAME,
            CONF_PASSWORD: PASSWORD
        },
    )
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
    assert result["errors"] == {"base": "wrong_login"}
    hass.config_entries.flow.async_abort(result["flow_id"])