2020-12-02 18:36:16 +00:00
|
|
|
"""Test AccuWeather system health."""
|
2024-03-08 18:16:21 +00:00
|
|
|
|
2020-12-02 18:36:16 +00:00
|
|
|
import asyncio
|
2024-05-06 17:41:48 +00:00
|
|
|
from unittest.mock import AsyncMock
|
2020-12-02 18:36:16 +00:00
|
|
|
|
|
|
|
from aiohttp import ClientError
|
|
|
|
|
2021-06-21 04:40:04 +00:00
|
|
|
from homeassistant.components.accuweather.const import DOMAIN
|
2023-02-08 11:16:23 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-12-02 18:36:16 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
2024-05-06 17:41:48 +00:00
|
|
|
from . import init_integration
|
|
|
|
|
2020-12-02 18:36:16 +00:00
|
|
|
from tests.common import get_system_health_info
|
2023-02-08 11:16:23 +00:00
|
|
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
2020-12-02 18:36:16 +00:00
|
|
|
|
|
|
|
|
2023-02-08 11:16:23 +00:00
|
|
|
async def test_accuweather_system_health(
|
2024-05-06 17:41:48 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
mock_accuweather_client: AsyncMock,
|
2023-02-08 11:16:23 +00:00
|
|
|
) -> None:
|
2020-12-02 18:36:16 +00:00
|
|
|
"""Test AccuWeather system health."""
|
|
|
|
aioclient_mock.get("https://dataservice.accuweather.com/", text="")
|
2024-05-06 17:41:48 +00:00
|
|
|
|
|
|
|
await init_integration(hass)
|
2020-12-02 18:36:16 +00:00
|
|
|
assert await async_setup_component(hass, "system_health", {})
|
2024-03-06 07:16:42 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-12-02 18:36:16 +00:00
|
|
|
|
|
|
|
info = await get_system_health_info(hass, DOMAIN)
|
|
|
|
|
|
|
|
for key, val in info.items():
|
|
|
|
if asyncio.iscoroutine(val):
|
|
|
|
info[key] = await val
|
|
|
|
|
|
|
|
assert info == {
|
|
|
|
"can_reach_server": "ok",
|
2024-05-06 17:41:48 +00:00
|
|
|
"remaining_requests": 10,
|
2020-12-02 18:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-08 11:16:23 +00:00
|
|
|
async def test_accuweather_system_health_fail(
|
2024-05-06 17:41:48 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
mock_accuweather_client: AsyncMock,
|
2023-02-08 11:16:23 +00:00
|
|
|
) -> None:
|
2020-12-02 18:36:16 +00:00
|
|
|
"""Test AccuWeather system health."""
|
|
|
|
aioclient_mock.get("https://dataservice.accuweather.com/", exc=ClientError)
|
2024-05-06 17:41:48 +00:00
|
|
|
|
|
|
|
await init_integration(hass)
|
2020-12-02 18:36:16 +00:00
|
|
|
assert await async_setup_component(hass, "system_health", {})
|
2024-03-06 07:16:42 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-12-02 18:36:16 +00:00
|
|
|
|
|
|
|
info = await get_system_health_info(hass, DOMAIN)
|
|
|
|
|
|
|
|
for key, val in info.items():
|
|
|
|
if asyncio.iscoroutine(val):
|
|
|
|
info[key] = await val
|
|
|
|
|
|
|
|
assert info == {
|
|
|
|
"can_reach_server": {"type": "failed", "error": "unreachable"},
|
2024-05-06 17:41:48 +00:00
|
|
|
"remaining_requests": 10,
|
2020-12-02 18:36:16 +00:00
|
|
|
}
|