* Copy google_sheets to google_assistant_sdk This is to improve diff of the next commit with the actual implementation. Commands used: cp -r homeassistant/components/google_sheets/ homeassistant/components/google_assistant_sdk/ cp -r tests/components/google_sheets/ tests/components/google_assistant_sdk/ find homeassistant/components/google_assistant_sdk/ tests/components/google_assistant_sdk/ -type f | xargs sed -i \ -e 's@google_sheets@google_assistant_sdk@g' \ -e 's@Google Sheets@Google Assistant SDK@g' \ -e 's@tkdrob@tronikos@g' * Google Assistant SDK integration Allows sending commands and broadcast messages to Google Assistant. * Remove unnecessary async_entry_has_scopes check * Bump gassist-text to fix protobuf dependency
82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
"""PyTest fixtures and test helpers."""
|
|
from collections.abc import Awaitable, Callable, Generator
|
|
import time
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.application_credentials import (
|
|
ClientCredential,
|
|
async_import_client_credential,
|
|
)
|
|
from homeassistant.components.google_assistant_sdk.const import DOMAIN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
ComponentSetup = Callable[[], Awaitable[None]]
|
|
|
|
CLIENT_ID = "1234"
|
|
CLIENT_SECRET = "5678"
|
|
|
|
|
|
@pytest.fixture
|
|
async def setup_credentials(hass: HomeAssistant) -> None:
|
|
"""Fixture to setup credentials."""
|
|
assert await async_setup_component(hass, "application_credentials", {})
|
|
await async_import_client_credential(
|
|
hass,
|
|
DOMAIN,
|
|
ClientCredential(CLIENT_ID, CLIENT_SECRET),
|
|
)
|
|
|
|
|
|
@pytest.fixture(name="scopes")
|
|
def mock_scopes() -> list[str]:
|
|
"""Fixture to set the scopes present in the OAuth token."""
|
|
return ["https://www.googleapis.com/auth/assistant-sdk-prototype"]
|
|
|
|
|
|
@pytest.fixture(name="expires_at")
|
|
def mock_expires_at() -> int:
|
|
"""Fixture to set the oauth token expiration time."""
|
|
return time.time() + 3600
|
|
|
|
|
|
@pytest.fixture(name="config_entry")
|
|
def mock_config_entry(expires_at: int, scopes: list[str]) -> MockConfigEntry:
|
|
"""Fixture for MockConfigEntry."""
|
|
return MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={
|
|
"auth_implementation": DOMAIN,
|
|
"token": {
|
|
"access_token": "mock-access-token",
|
|
"refresh_token": "mock-refresh-token",
|
|
"expires_at": expires_at,
|
|
"scope": " ".join(scopes),
|
|
},
|
|
},
|
|
)
|
|
|
|
|
|
@pytest.fixture(name="setup_integration")
|
|
async def mock_setup_integration(
|
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
|
) -> Generator[ComponentSetup, None, None]:
|
|
"""Fixture for setting up the component."""
|
|
config_entry.add_to_hass(hass)
|
|
|
|
assert await async_setup_component(hass, "application_credentials", {})
|
|
await async_import_client_credential(
|
|
hass,
|
|
DOMAIN,
|
|
ClientCredential("client-id", "client-secret"),
|
|
DOMAIN,
|
|
)
|
|
|
|
async def func() -> None:
|
|
assert await async_setup_component(hass, DOMAIN, {})
|
|
await hass.async_block_till_done()
|
|
|
|
yield func
|