Ejemplo n.º 1
0
async def test_reauth_account_locked(hass: HomeAssistant) -> None:
    """Test we show user form on account_locked error."""
    with patch(
            "homeassistant.components.mazda.config_flow.MazdaAPI.validate_credentials",
            side_effect=MazdaAccountLockedException("Account locked"),
    ):
        result = await hass.config_entries.flow.async_init(
            DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT)

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

        result2 = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            FIXTURE_USER_INPUT_REAUTH,
        )
        await hass.async_block_till_done()

        assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result2["step_id"] == "reauth"
        assert result2["errors"] == {"base": "account_locked"}
Ejemplo n.º 2
0
async def test_form_account_locked(hass: HomeAssistant) -> None:
    """Test we handle account locked error."""
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": config_entries.SOURCE_USER})

    assert result["type"] == data_entry_flow.FlowResultType.FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {}

    with patch(
            "homeassistant.components.mazda.config_flow.MazdaAPI.validate_credentials",
            side_effect=MazdaAccountLockedException("Account locked"),
    ):
        result2 = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            FIXTURE_USER_INPUT,
        )
        await hass.async_block_till_done()

    assert result2["type"] == data_entry_flow.FlowResultType.FORM
    assert result2["step_id"] == "user"
    assert result2["errors"] == {"base": "account_locked"}
Ejemplo n.º 3
0
async def test_reauth_account_locked(hass: HomeAssistant) -> None:
    """Test we show user form on account_locked error."""
    mock_config = MockConfigEntry(
        domain=DOMAIN,
        unique_id=FIXTURE_USER_INPUT[CONF_EMAIL],
        data=FIXTURE_USER_INPUT,
    )
    mock_config.add_to_hass(hass)

    with patch(
            "homeassistant.components.mazda.config_flow.MazdaAPI.validate_credentials",
            side_effect=MazdaAccountLockedException("Account locked"),
    ), patch(
            "homeassistant.components.mazda.async_setup_entry",
            return_value=True,
    ):
        result = await hass.config_entries.flow.async_init(
            DOMAIN,
            context={
                "source": config_entries.SOURCE_REAUTH,
                "entry_id": mock_config.entry_id,
            },
            data=FIXTURE_USER_INPUT,
        )

        assert result["type"] == data_entry_flow.FlowResultType.FORM
        assert result["step_id"] == "user"

        result2 = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            FIXTURE_USER_INPUT_REAUTH,
        )
        await hass.async_block_till_done()

        assert result2["type"] == data_entry_flow.FlowResultType.FORM
        assert result2["step_id"] == "user"
        assert result2["errors"] == {"base": "account_locked"}