2020-12-02 19:36:16 +01:00
|
|
|
"""Test AccuWeather system health."""
|
2024-03-08 19:16:21 +01:00
|
|
|
|
2020-12-02 19:36:16 +01:00
|
|
|
import asyncio
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import Mock
|
2020-12-02 19:36:16 +01:00
|
|
|
|
|
|
|
from aiohttp import ClientError
|
|
|
|
|
2024-04-24 10:30:57 +02:00
|
|
|
from homeassistant.components.accuweather import AccuWeatherData
|
2021-06-21 06:40:04 +02:00
|
|
|
from homeassistant.components.accuweather.const import DOMAIN
|
2023-02-08 12:16:23 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-12-02 19:36:16 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from tests.common import get_system_health_info
|
2023-02-08 12:16:23 +01:00
|
|
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
2020-12-02 19:36:16 +01:00
|
|
|
|
|
|
|
|
2023-02-08 12:16:23 +01:00
|
|
|
async def test_accuweather_system_health(
|
|
|
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
|
|
) -> None:
|
2020-12-02 19:36:16 +01:00
|
|
|
"""Test AccuWeather system health."""
|
|
|
|
aioclient_mock.get("https://dataservice.accuweather.com/", text="")
|
|
|
|
hass.config.components.add(DOMAIN)
|
|
|
|
assert await async_setup_component(hass, "system_health", {})
|
2024-03-05 21:16:42 -10:00
|
|
|
await hass.async_block_till_done()
|
2020-12-02 19:36:16 +01:00
|
|
|
|
|
|
|
hass.data[DOMAIN] = {}
|
2024-04-24 10:30:57 +02:00
|
|
|
hass.data[DOMAIN]["0123xyz"] = AccuWeatherData(
|
|
|
|
coordinator_observation=Mock(accuweather=Mock(requests_remaining="42")),
|
|
|
|
coordinator_daily_forecast=Mock(),
|
|
|
|
)
|
2020-12-02 19:36:16 +01: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",
|
|
|
|
"remaining_requests": "42",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-08 12:16:23 +01:00
|
|
|
async def test_accuweather_system_health_fail(
|
|
|
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
|
|
) -> None:
|
2020-12-02 19:36:16 +01:00
|
|
|
"""Test AccuWeather system health."""
|
|
|
|
aioclient_mock.get("https://dataservice.accuweather.com/", exc=ClientError)
|
|
|
|
hass.config.components.add(DOMAIN)
|
|
|
|
assert await async_setup_component(hass, "system_health", {})
|
2024-03-05 21:16:42 -10:00
|
|
|
await hass.async_block_till_done()
|
2020-12-02 19:36:16 +01:00
|
|
|
|
|
|
|
hass.data[DOMAIN] = {}
|
2024-04-24 10:30:57 +02:00
|
|
|
hass.data[DOMAIN]["0123xyz"] = AccuWeatherData(
|
|
|
|
coordinator_observation=Mock(accuweather=Mock(requests_remaining="0")),
|
|
|
|
coordinator_daily_forecast=Mock(),
|
|
|
|
)
|
2020-12-02 19:36:16 +01: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"},
|
|
|
|
"remaining_requests": "0",
|
|
|
|
}
|