mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Improve Google Health config flow error messages (#179940)
Co-authored-by: Home Assistant Developer <hello@home-assistant.io>
This commit is contained in:
co-authored by
Home Assistant Developer
parent
52e0c3c6a7
commit
ef8e89180b
@@ -5,7 +5,8 @@ from unittest.mock import AsyncMock, patch
|
||||
from google_health_api.const import HealthApiScope
|
||||
from google_health_api.exceptions import (
|
||||
GoogleHealthApiError,
|
||||
HealthApiForbiddenException,
|
||||
HealthApiScopeInsufficientException,
|
||||
HealthApiServiceDisabledException,
|
||||
)
|
||||
from google_health_api.model import Identity
|
||||
import pytest
|
||||
@@ -243,8 +244,8 @@ async def test_config_flow_api_not_enabled(
|
||||
mock_google_health_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test config flow aborts if the Google Health API is not enabled."""
|
||||
mock_google_health_client.get_identity.side_effect = HealthApiForbiddenException(
|
||||
"Forbidden"
|
||||
mock_google_health_client.get_identity.side_effect = (
|
||||
HealthApiServiceDisabledException
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -280,6 +281,50 @@ async def test_config_flow_api_not_enabled(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"current_request_with_host", "mock_setup_entry", "setup_credentials"
|
||||
)
|
||||
async def test_config_flow_scope_insufficient(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
mock_google_health_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test config flow aborts if the OAuth token has insufficient scope."""
|
||||
mock_google_health_client.get_identity.side_effect = (
|
||||
HealthApiScopeInsufficientException
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
state = config_entry_oauth2_flow._encode_jwt(
|
||||
hass,
|
||||
{
|
||||
"flow_id": result["flow_id"],
|
||||
"redirect_uri": "https://example.com/auth/external/callback",
|
||||
},
|
||||
)
|
||||
|
||||
client = await hass_client_no_auth()
|
||||
await client.get(f"/auth/external/callback?code=abcd&state={state}")
|
||||
|
||||
aioclient_mock.post(
|
||||
OAUTH2_TOKEN,
|
||||
json={
|
||||
"refresh_token": "mock-refresh-token",
|
||||
"access_token": "mock-access-token",
|
||||
"type": "Bearer",
|
||||
"expires_in": 60,
|
||||
"scope": " ".join(OAUTH_SCOPES),
|
||||
},
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "missing_profile_scope"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"current_request_with_host", "mock_setup_entry", "setup_credentials"
|
||||
)
|
||||
@@ -321,7 +366,7 @@ async def test_config_flow_missing_health_user_id(
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
assert result["reason"] == "missing_profile_scope"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
|
||||
Reference in New Issue
Block a user