示例#1
0
async def test_title_failure_fallback(hass, oauth):
    """Test exception handling when determining the structure names."""
    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)

    mock_subscriber = AsyncMock(FakeSubscriber)
    mock_subscriber.async_get_device_manager.side_effect = AuthException()

    with patch(
        "homeassistant.components.nest.api.GoogleNestSubscriber",
        return_value=mock_subscriber,
    ):
        result = await oauth.async_configure(result, {"code": "1234"})
        await oauth.async_pubsub_flow(result)
        entry = await oauth.async_finish_setup(
            result, {"cloud_project_id": CLOUD_PROJECT_ID}
        )
        await hass.async_block_till_done()

    assert entry.title == "OAuth for Apps"
    assert "token" in entry.data
    assert "subscriber_id" in entry.data
    assert entry.data["cloud_project_id"] == CLOUD_PROJECT_ID
async def test_subscriber_auth_failure(hass, caplog):
    """Test configuration error."""
    with patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
            side_effect=AuthException(),
    ):
        result = await async_setup_sdm(hass, CONFIG)
        assert result

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

    flows = hass.config_entries.flow.async_progress()
    assert len(flows) == 1
    assert flows[0]["step_id"] == "reauth_confirm"
示例#3
0
async def test_pubsub_subscription_auth_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"})

    mock_subscriber.create_subscription.side_effect = AuthException()

    await oauth.async_pubsub_flow(result)
    result = await oauth.async_configure(
        result, {"cloud_project_id": CLOUD_PROJECT_ID})

    assert result["type"] == "abort"
    assert result["reason"] == "invalid_access_token"
示例#4
0
async def test_pubsub_subscription_auth_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"})
    with patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.create_subscription",
            side_effect=AuthException(),
    ):
        await oauth.async_pubsub_flow(result)
        result = await oauth.async_configure(
            result, {"cloud_project_id": CLOUD_PROJECT_ID})
        await hass.async_block_till_done()

    assert result["type"] == "abort"
    assert result["reason"] == "invalid_access_token"
示例#5
0
async def test_title_failure_fallback(hass, oauth, setup_platform,
                                      mock_subscriber):
    """Test exception handling when determining the structure names."""
    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)

    mock_subscriber.async_get_device_manager.side_effect = AuthException()

    result = await oauth.async_configure(result, {"code": "1234"})
    await oauth.async_pubsub_flow(result)
    entry = await oauth.async_finish_setup(
        result, {"cloud_project_id": CLOUD_PROJECT_ID})

    assert entry.title == "OAuth for Apps"
    assert "token" in entry.data
    assert "subscriber_id" in entry.data
    assert entry.data["cloud_project_id"] == CLOUD_PROJECT_ID
示例#6
0
            "homeassistant.components.nest.api.GoogleNestSubscriber.start_async"
    ), patch(
            "homeassistant.components.nest.api.GoogleNestSubscriber.async_get_device_manager",
            side_effect=ApiException(),
    ):
        await setup_base_platform()

    assert len(error_caplog.messages) == 1
    assert "Device manager error:" in error_caplog.text

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


@pytest.mark.parametrize("subscriber_side_effect", [AuthException()])
async def test_subscriber_auth_failure(hass, caplog, setup_base_platform,
                                       failing_subscriber):
    """Test subscriber throws an authentication error."""
    await setup_base_platform()

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

    flows = hass.config_entries.flow.async_progress()
    assert len(flows) == 1
    assert flows[0]["step_id"] == "reauth_confirm"


@pytest.mark.parametrize("subscriber_id", [(None)])