1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fix bug in fitbit credential import for expired tokens (#103024)

* Fix bug in fitbit credential import on token refresh

* Use stable test ids

* Update homeassistant/components/fitbit/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Allen Porter
2023-10-29 14:26:10 -07:00
committed by GitHub
parent b323295aa1
commit d75f1b2b3e
3 changed files with 23 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
from collections.abc import Awaitable, Callable
from http import HTTPStatus
import time
from typing import Any
from unittest.mock import patch
@@ -16,9 +17,7 @@ from homeassistant.helpers import config_entry_oauth2_flow, issue_registry as ir
from .conftest import (
CLIENT_ID,
FAKE_ACCESS_TOKEN,
FAKE_AUTH_IMPL,
FAKE_REFRESH_TOKEN,
PROFILE_API_URL,
PROFILE_USER_ID,
SERVER_ACCESS_TOKEN,
@@ -204,6 +203,11 @@ async def test_config_entry_already_exists(
assert result.get("reason") == "already_configured"
@pytest.mark.parametrize(
"token_expiration_time",
[time.time() + 86400, time.time() - 86400],
ids=("token_active", "token_expired"),
)
async def test_import_fitbit_config(
hass: HomeAssistant,
fitbit_config_setup: None,
@@ -235,16 +239,20 @@ async def test_import_fitbit_config(
assert config_entry.unique_id == PROFILE_USER_ID
data = dict(config_entry.data)
# Verify imported values from fitbit.conf and configuration.yaml and
# that the token is updated.
assert "token" in data
expires_at = data["token"]["expires_at"]
assert expires_at > time.time()
del data["token"]["expires_at"]
# Verify imported values from fitbit.conf and configuration.yaml
assert dict(config_entry.data) == {
"auth_implementation": DOMAIN,
"clock_format": "24H",
"monitored_resources": ["activities/steps"],
"token": {
"access_token": FAKE_ACCESS_TOKEN,
"refresh_token": FAKE_REFRESH_TOKEN,
"access_token": "server-access-token",
"refresh_token": "server-refresh-token",
"scope": "activity heartrate nutrition profile settings sleep weight",
},
"unit_system": "default",
}