mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Test the google tasks api connection in setup (#132657)
Improve google tasks setup
This commit is contained in:
@ -2,8 +2,11 @@
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
import http
|
||||
from http import HTTPStatus
|
||||
import time
|
||||
from unittest.mock import Mock
|
||||
|
||||
from httplib2 import Response
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.google_tasks import DOMAIN
|
||||
@ -11,15 +14,19 @@ from homeassistant.components.google_tasks.const import OAUTH2_TOKEN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import LIST_TASK_LIST_RESPONSE
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_responses", [[LIST_TASK_LIST_RESPONSE]])
|
||||
async def test_setup(
|
||||
hass: HomeAssistant,
|
||||
integration_setup: Callable[[], Awaitable[bool]],
|
||||
config_entry: MockConfigEntry,
|
||||
setup_credentials: None,
|
||||
mock_http_response: Mock,
|
||||
) -> None:
|
||||
"""Test successful setup and unload."""
|
||||
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
@ -35,12 +42,14 @@ async def test_setup(
|
||||
|
||||
|
||||
@pytest.mark.parametrize("expires_at", [time.time() - 3600], ids=["expired"])
|
||||
@pytest.mark.parametrize("api_responses", [[LIST_TASK_LIST_RESPONSE]])
|
||||
async def test_expired_token_refresh_success(
|
||||
hass: HomeAssistant,
|
||||
integration_setup: Callable[[], Awaitable[bool]],
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
config_entry: MockConfigEntry,
|
||||
setup_credentials: None,
|
||||
mock_http_response: Mock,
|
||||
) -> None:
|
||||
"""Test expired token is refreshed."""
|
||||
|
||||
@ -98,3 +107,22 @@ async def test_expired_token_refresh_failure(
|
||||
await integration_setup()
|
||||
|
||||
assert config_entry.state is expected_state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"response_handler",
|
||||
[
|
||||
([(Response({"status": HTTPStatus.INTERNAL_SERVER_ERROR}), b"")]),
|
||||
],
|
||||
)
|
||||
async def test_setup_error(
|
||||
hass: HomeAssistant,
|
||||
setup_credentials: None,
|
||||
integration_setup: Callable[[], Awaitable[bool]],
|
||||
mock_http_response: Mock,
|
||||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test an error returned by the server when setting up the platform."""
|
||||
|
||||
assert not await integration_setup()
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
Reference in New Issue
Block a user