示例#1
0
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=SubscriberException(),
    ):
        assert await hass.config_entries.async_remove(entry.entry_id)

    entries = hass.config_entries.async_entries(DOMAIN)
    assert not entries
示例#2
0
async def test_setup_susbcriber_failure(hass, caplog):
    """Test configuration error."""
    with patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
            side_effect=SubscriberException(),
    ), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
        result = await async_setup_sdm(hass)
        assert result
        assert "Subscriber error:" in caplog.text

    entries = hass.config_entries.async_entries(DOMAIN)
    assert len(entries) == 1
    assert entries[0].state is ConfigEntryState.SETUP_RETRY
示例#3
0
async def test_setup_susbcriber_failure(hass, hass_client, config_entry,
                                        setup_base_platform):
    """Test configuration error."""
    with patch(
            "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation"
    ), patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
            side_effect=SubscriberException(),
    ):
        await setup_base_platform()

    assert config_entry.state is ConfigEntryState.SETUP_RETRY

    assert await get_diagnostics_for_config_entry(
        hass, hass_client, config_entry) == {
            "error": "No subscriber configured"
        }
示例#4
0
async def test_setup_susbcriber_failure(hass, hass_client):
    """Test configuration error."""
    config_entry = create_config_entry()
    config_entry.add_to_hass(hass)
    with patch(
            "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation"
    ), patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
            side_effect=SubscriberException(),
    ):
        assert await async_setup_component(hass, DOMAIN, CONFIG)

    assert config_entry.state is ConfigEntryState.SETUP_RETRY

    assert await get_diagnostics_for_config_entry(
        hass, hass_client, config_entry) == {
            "error": "No subscriber configured"
        }
示例#5
0
async def test_pubsub_subscription_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 = SubscriberException()

    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"] == "subscriber_error"
示例#6
0
async def test_remove_entry_delete_subscriber_failure(hass, nest_test_config,
                                                      setup_base_platform):
    """Test a failure when deleting the subscription."""
    with patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber",
            return_value=FakeSubscriber(),
    ):
        await setup_base_platform()

    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=SubscriberException(),
    ) as delete:
        assert await hass.config_entries.async_remove(entry.entry_id)
        assert delete.called

    entries = hass.config_entries.async_entries(DOMAIN)
    assert not entries
示例#7
0
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=SubscriberException(),
    ):
        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"
示例#8
0
@pytest.mark.parametrize("subscriber_id", [("invalid-subscriber-format")])
async def test_setup_configuration_failure(hass, caplog, subscriber_id,
                                           setup_base_platform):
    """Test configuration error."""
    await setup_base_platform()

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

    # This error comes from the python google-nest-sdm library, as a check added
    # to prevent common misconfigurations (e.g. confusing topic and subscriber)
    assert "Subscription misconfigured. Expected subscriber_id" in caplog.text


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

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


async def test_setup_device_manager_failure(hass, error_caplog,
                                            setup_base_platform):
    """Test device manager api failure."""
    with patch(