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

Add logs to Cloud component support package (#138230)

* Add logs to Cloud component support package

* Add section for logs

* Replace list with deque

* Copy the deque to avoid mutation during iteration
This commit is contained in:
Abílio Costa
2025-02-11 22:05:19 +00:00
committed by GitHub
parent 0ffbe076be
commit 48b8ec01e3
6 changed files with 103 additions and 4 deletions

View File

@@ -2,12 +2,15 @@
from collections.abc import Callable, Coroutine
from copy import deepcopy
import datetime
from http import HTTPStatus
import json
import logging
from typing import Any
from unittest.mock import AsyncMock, MagicMock, Mock, PropertyMock, patch
import aiohttp
from freezegun.api import FrozenDateTimeFactory
from hass_nabucasa import thingtalk
from hass_nabucasa.auth import (
InvalidTotpCode,
@@ -1869,15 +1872,18 @@ async def test_logout_view_dispatch_event(
assert async_dispatcher_send_mock.mock_calls[0][1][2] == {"type": "logout"}
@patch("homeassistant.components.cloud.helpers.FixedSizeQueueLogHandler.MAX_RECORDS", 3)
async def test_download_support_package(
hass: HomeAssistant,
cloud: MagicMock,
set_cloud_prefs: Callable[[dict[str, Any]], Coroutine[Any, Any, None]],
hass_client: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
freezer: FrozenDateTimeFactory,
snapshot: SnapshotAssertion,
) -> None:
"""Test downloading a support package file."""
aioclient_mock.get("https://cloud.bla.com/status", text="")
aioclient_mock.get(
"https://cert-server/directory", exc=Exception("Unexpected exception")
@@ -1936,6 +1942,16 @@ async def test_download_support_package(
}
)
now = dt_util.utcnow()
freezer.move_to(datetime.datetime.fromisoformat("2025-02-10T12:00:00.0+00:00"))
logging.getLogger("hass_nabucasa.iot").info(
"This message will be dropped since this test patches MAX_RECORDS"
)
logging.getLogger("hass_nabucasa.iot").info("Hass nabucasa log")
logging.getLogger("snitun.utils.aiohttp_client").warning("Snitun log")
logging.getLogger("homeassistant.components.cloud.client").error("Cloud log")
freezer.move_to(now) # Reset time otherwise hass_client auth fails
cloud_client = await hass_client()
with (
patch.object(hass.config, "config_dir", new="config"),