mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add application credentials platform for google calendar integration (#71808)
* Add google application_credentials platform * Further simplify custom auth implementation overrides * Add test coverage in application_credentials * Simplify wording in a comment * Remove unused imports accidentally left from merge * Wrap lines that are too long for style guide * Move application credential loading to only where it is needed * Leave CLIENT_ID and CLIENT_SECRET as required.
This commit is contained in:
@@ -14,6 +14,7 @@ from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.application_credentials import (
|
||||
CONF_AUTH_DOMAIN,
|
||||
DOMAIN,
|
||||
AuthImplementation,
|
||||
AuthorizationServer,
|
||||
ClientCredential,
|
||||
async_import_client_credential,
|
||||
@@ -64,12 +65,14 @@ async def setup_application_credentials_integration(
|
||||
) -> None:
|
||||
"""Set up a fake application_credentials integration."""
|
||||
hass.config.components.add(domain)
|
||||
mock_platform_impl = Mock(
|
||||
async_get_authorization_server=AsyncMock(return_value=authorization_server),
|
||||
)
|
||||
del mock_platform_impl.async_get_auth_implementation # return False on hasattr
|
||||
mock_platform(
|
||||
hass,
|
||||
f"{domain}.application_credentials",
|
||||
Mock(
|
||||
async_get_authorization_server=AsyncMock(return_value=authorization_server),
|
||||
),
|
||||
mock_platform_impl,
|
||||
)
|
||||
|
||||
|
||||
@@ -585,6 +588,7 @@ async def test_websocket_without_authorization_server(
|
||||
# Platform does not implemenent async_get_authorization_server
|
||||
platform = Mock()
|
||||
del platform.async_get_authorization_server
|
||||
del platform.async_get_auth_implementation
|
||||
mock_platform(
|
||||
hass,
|
||||
f"{TEST_DOMAIN}.application_credentials",
|
||||
@@ -611,6 +615,45 @@ async def test_websocket_without_authorization_server(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("config_credential", [DEVELOPER_CREDENTIAL])
|
||||
async def test_platform_with_auth_implementation(
|
||||
hass,
|
||||
hass_client_no_auth,
|
||||
aioclient_mock,
|
||||
oauth_fixture,
|
||||
config_credential,
|
||||
import_config_credential,
|
||||
authorization_server,
|
||||
):
|
||||
"""Test config flow with custom OAuth2 implementation."""
|
||||
|
||||
assert await async_setup_component(hass, "application_credentials", {})
|
||||
hass.config.components.add(TEST_DOMAIN)
|
||||
|
||||
async def get_auth_impl(
|
||||
hass: HomeAssistant, auth_domain: str, credential: ClientCredential
|
||||
) -> config_entry_oauth2_flow.AbstractOAuth2Implementation:
|
||||
return AuthImplementation(hass, auth_domain, credential, authorization_server)
|
||||
|
||||
mock_platform_impl = Mock(
|
||||
async_get_auth_implementation=get_auth_impl,
|
||||
)
|
||||
del mock_platform_impl.async_get_authorization_server
|
||||
mock_platform(
|
||||
hass,
|
||||
f"{TEST_DOMAIN}.application_credentials",
|
||||
mock_platform_impl,
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result.get("type") == data_entry_flow.RESULT_TYPE_EXTERNAL_STEP
|
||||
result = await oauth_fixture.complete_external_step(result)
|
||||
# Uses the imported auth domain for compatibility
|
||||
assert result["data"].get("auth_implementation") == TEST_DOMAIN
|
||||
|
||||
|
||||
async def test_websocket_integration_list(ws_client: ClientFixture):
|
||||
"""Test websocket integration list command."""
|
||||
client = await ws_client()
|
||||
|
||||
Reference in New Issue
Block a user