async def test_remove_entry_delete_subscriber_failure(hass, caplog): """Test a failure when deleting the subscription.""" config = copy.deepcopy(CONFIG) subscriber_id = config[DOMAIN]["subscriber_id"] del config[DOMAIN]["subscriber_id"] config_entry = create_config_entry(hass) data = {**config_entry.data} data["subscriber_id"] = subscriber_id hass.config_entries.async_update_entry(config_entry, data=data) await async_setup_sdm_platform(hass, PLATFORM, with_config=False) entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 entry = entries[0] assert entry.state is ConfigEntryState.LOADED with patch( "homeassistant.components.nest.api.GoogleNestSubscriber.delete_subscription", side_effect=GoogleNestException(), ): assert await hass.config_entries.async_remove(entry.entry_id) entries = hass.config_entries.async_entries(DOMAIN) assert not entries
async def test_setup_susbcriber_failure(hass, caplog): """Test configuration error.""" with patch( "homeassistant.components.nest.GoogleNestSubscriber.start_async", side_effect=GoogleNestException(), ), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"): await async_setup_sdm(hass) assert "Subscriber error:" in caplog.text entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state == ENTRY_STATE_SETUP_RETRY
async def test_setup_device_manager_failure(hass, caplog): """Test configuration error.""" with patch("homeassistant.components.nest.GoogleNestSubscriber.start_async"), patch( "homeassistant.components.nest.GoogleNestSubscriber.async_get_device_manager", side_effect=GoogleNestException(), ), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"): result = await async_setup_sdm(hass) assert result assert len(caplog.messages) == 1 assert "Device manager error:" in caplog.text entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state is ConfigEntryState.SETUP_RETRY
async def test_pubsub_subscription_failure(hass, oauth): """Check flow that creates a pub/sub subscription.""" assert await async_setup_configflow(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}) result = await oauth.async_pick_flow(result, APP_AUTH_DOMAIN) await oauth.async_oauth_app_flow(result) result = await oauth.async_configure(result, {"code": "1234"}) await oauth.async_pubsub_flow(result) with patch( "homeassistant.components.nest.api.GoogleNestSubscriber.create_subscription", side_effect=GoogleNestException(), ): result = await oauth.async_configure( result, {"cloud_project_id": CLOUD_PROJECT_ID}) await hass.async_block_till_done() assert result["type"] == "form" assert "errors" in result assert "cloud_project_id" in result["errors"] assert result["errors"]["cloud_project_id"] == "subscriber_error"