async def test_update_auth_failure(hass: HomeAssistant): """Test auth failure during data update.""" with patch( "homeassistant.components.mazda.MazdaAPI.validate_credentials", return_value=True, ), patch("homeassistant.components.mazda.MazdaAPI.get_vehicles", return_value={}): config_entry = MockConfigEntry(domain=DOMAIN, data=FIXTURE_USER_INPUT) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state == ENTRY_STATE_LOADED coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR] with patch( "homeassistant.components.mazda.MazdaAPI.validate_credentials", side_effect=MazdaAuthenticationException("Login failed"), ), patch( "homeassistant.components.mazda.MazdaAPI.get_vehicles", side_effect=MazdaAuthenticationException("Login failed"), ): await coordinator.async_refresh() await hass.async_block_till_done() flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["step_id"] == "reauth"
async def test_init_auth_failure(opp: OpenPeerPower): """Test auth failure during setup.""" with patch( "openpeerpower.components.mazda.MazdaAPI.validate_credentials", side_effect=MazdaAuthenticationException("Login failed"), ): config_entry = MockConfigEntry(domain=DOMAIN, data=FIXTURE_USER_INPUT) config_entry.add_to_opp(opp) await opp.config_entries.async_setup(config_entry.entry_id) await opp.async_block_till_done() entries = opp.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state is ConfigEntryState.SETUP_ERROR flows = opp.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["step_id"] == "user"
async def test_init_auth_failure(hass: HomeAssistant): """Test auth failure during setup.""" with patch( "homeassistant.components.mazda.MazdaAPI.validate_credentials", side_effect=MazdaAuthenticationException("Login failed"), ): config_entry = MockConfigEntry(domain=DOMAIN, data=FIXTURE_USER_INPUT) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state == ENTRY_STATE_SETUP_ERROR flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["step_id"] == "user"
async def test_update_auth_failure(hass: HomeAssistant): """Test auth failure during data update.""" get_vehicles_fixture = json.loads(load_fixture("mazda/get_vehicles.json")) get_vehicle_status_fixture = json.loads( load_fixture("mazda/get_vehicle_status.json") ) with patch( "homeassistant.components.mazda.MazdaAPI.validate_credentials", return_value=True, ), patch( "homeassistant.components.mazda.MazdaAPI.get_vehicles", return_value=get_vehicles_fixture, ), patch( "homeassistant.components.mazda.MazdaAPI.get_vehicle_status", return_value=get_vehicle_status_fixture, ): config_entry = MockConfigEntry(domain=DOMAIN, data=FIXTURE_USER_INPUT) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state is ConfigEntryState.LOADED with patch( "homeassistant.components.mazda.MazdaAPI.get_vehicles", side_effect=MazdaAuthenticationException("Login failed"), ): async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=181)) await hass.async_block_till_done() flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["step_id"] == "user"