Increase test coverage for google tasks init (#133252)

This commit is contained in:
Allen Porter 2024-12-15 11:23:56 -08:00 committed by GitHub
parent 81c12db6cd
commit b77e42e8f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View File

@ -31,16 +31,12 @@ rules:
# Silver # Silver
log-when-unavailable: done log-when-unavailable: done
config-entry-unloading: done config-entry-unloading: done
reauthentication-flow: reauthentication-flow: done
status: todo
comment: Missing a test that reauthenticates with the wrong account
action-exceptions: done action-exceptions: done
docs-installation-parameters: todo docs-installation-parameters: todo
integration-owner: done integration-owner: done
parallel-updates: done parallel-updates: done
test-coverage: test-coverage: done
status: todo
comment: Test coverage for __init__.py is not above 95% yet
docs-configuration-parameters: todo docs-configuration-parameters: todo
entity-unavailable: done entity-unavailable: done

View File

@ -6,6 +6,7 @@ from http import HTTPStatus
import time import time
from unittest.mock import Mock from unittest.mock import Mock
from aiohttp import ClientError
from httplib2 import Response from httplib2 import Response
import pytest import pytest
@ -72,20 +73,28 @@ async def test_expired_token_refresh_success(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("expires_at", "status", "expected_state"), ("expires_at", "status", "exc", "expected_state"),
[ [
( (
time.time() - 3600, time.time() - 3600,
http.HTTPStatus.UNAUTHORIZED, http.HTTPStatus.UNAUTHORIZED,
None,
ConfigEntryState.SETUP_ERROR, ConfigEntryState.SETUP_ERROR,
), ),
( (
time.time() - 3600, time.time() - 3600,
http.HTTPStatus.INTERNAL_SERVER_ERROR, http.HTTPStatus.INTERNAL_SERVER_ERROR,
None,
ConfigEntryState.SETUP_RETRY,
),
(
time.time() - 3600,
None,
ClientError("error"),
ConfigEntryState.SETUP_RETRY, ConfigEntryState.SETUP_RETRY,
), ),
], ],
ids=["unauthorized", "internal_server_error"], ids=["unauthorized", "internal_server_error", "client_error"],
) )
async def test_expired_token_refresh_failure( async def test_expired_token_refresh_failure(
hass: HomeAssistant, hass: HomeAssistant,
@ -93,7 +102,8 @@ async def test_expired_token_refresh_failure(
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
setup_credentials: None, setup_credentials: None,
status: http.HTTPStatus, status: http.HTTPStatus | None,
exc: Exception | None,
expected_state: ConfigEntryState, expected_state: ConfigEntryState,
) -> None: ) -> None:
"""Test failure while refreshing token with a transient error.""" """Test failure while refreshing token with a transient error."""
@ -102,6 +112,7 @@ async def test_expired_token_refresh_failure(
aioclient_mock.post( aioclient_mock.post(
OAUTH2_TOKEN, OAUTH2_TOKEN,
status=status, status=status,
exc=exc,
) )
await integration_setup() await integration_setup()