async def test_subscriber_configuration_failure(hass, caplog):
    """Test configuration error."""
    with patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
            side_effect=ConfigurationException(),
    ), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
        result = await async_setup_sdm(hass, CONFIG)
        assert result
        assert "Configuration error: " in caplog.text

    entries = hass.config_entries.async_entries(DOMAIN)
    assert len(entries) == 1
    assert entries[0].state is ConfigEntryState.SETUP_ERROR
Esempio n. 2
0
async def test_pubsub_subscription_configuration_failure(
        hass, oauth, setup_platform, mock_subscriber):
    """Check flow that creates a pub/sub subscription."""
    await setup_platform()

    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)

    mock_subscriber.create_subscription.side_effect = ConfigurationException()
    result = await oauth.async_configure(
        result, {"cloud_project_id": CLOUD_PROJECT_ID})

    assert result["type"] == "form"
    assert "errors" in result
    assert "cloud_project_id" in result["errors"]
    assert result["errors"]["cloud_project_id"] == "bad_project_id"
Esempio n. 3
0
async def test_pubsub_subscription_configuration_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=ConfigurationException(),
    ):
        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"] == "bad_project_id"
Esempio n. 4
0

@pytest.mark.parametrize("subscriber_id", [(None)])
async def test_setup_missing_subscriber_id(hass, warning_caplog,
                                           setup_base_platform):
    """Test missing susbcriber id from configuration."""
    await setup_base_platform()
    assert "Configuration option" in warning_caplog.text

    entries = hass.config_entries.async_entries(DOMAIN)
    assert len(entries) == 1
    assert entries[0].state is ConfigEntryState.SETUP_ERROR


@pytest.mark.parametrize("subscriber_side_effect",
                         [(ConfigurationException())])
async def test_subscriber_configuration_failure(hass, error_caplog,
                                                setup_base_platform,
                                                failing_subscriber):
    """Test configuration error."""
    await setup_base_platform()
    assert "Configuration error: " in error_caplog.text

    entries = hass.config_entries.async_entries(DOMAIN)
    assert len(entries) == 1
    assert entries[0].state is ConfigEntryState.SETUP_ERROR


@pytest.mark.parametrize("nest_test_config",
                         [NestTestConfig(config={}, config_entry_data=None)])
async def test_empty_config(hass, error_caplog, config, setup_platform):