async def test_login_failed(hass: HomeAssistant, service: MagicMock): """Test when we have errors during login.""" service.return_value.login = Mock( side_effect=(SynologyDSMLoginInvalidException(USERNAME)) ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {CONF_USERNAME: "******"}
async def test_reauth_triggered(hass: HomeAssistant): """Test if reauthentication flow is triggered.""" with patch( "homeassistant.components.synology_dsm.SynoApi.async_setup", side_effect=SynologyDSMLoginInvalidException(USERNAME), ), patch( "homeassistant.components.synology_dsm.config_flow.SynologyDSMFlowHandler.async_step_reauth", return_value={"type": data_entry_flow.RESULT_TYPE_FORM}, ) as mock_async_step_reauth: entry = MockConfigEntry( domain=DOMAIN, data={ CONF_HOST: HOST, CONF_PORT: PORT, CONF_SSL: USE_SSL, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD, CONF_MAC: MACS[0], }, ) entry.add_to_hass(hass) assert not await hass.config_entries.async_setup(entry.entry_id) mock_async_step_reauth.assert_called_once()