1
0
mirror of https://github.com/home-assistant/core.git synced 2026-03-01 14:25:31 +00:00
Files
core/tests/components/uptimerobot/test_diagnostics.py
2026-02-12 21:28:11 +01:00

76 lines
2.0 KiB
Python

"""Test UptimeRobot diagnostics."""
import json
from unittest.mock import patch
from pyuptimerobot import API_PATH_USER_ME, UptimeRobotException
from homeassistant.core import HomeAssistant
from .common import (
MOCK_UPTIMEROBOT_ACCOUNT,
MOCK_UPTIMEROBOT_API_KEY,
MOCK_UPTIMEROBOT_EMAIL,
mock_uptimerobot_api_response,
setup_uptimerobot_integration,
)
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
) -> None:
"""Test config entry diagnostics."""
entry = await setup_uptimerobot_integration(hass)
with patch(
"pyuptimerobot.UptimeRobot.async_get_account_details",
return_value=mock_uptimerobot_api_response(
api_path=API_PATH_USER_ME,
data=MOCK_UPTIMEROBOT_ACCOUNT,
),
):
result = await get_diagnostics_for_config_entry(
hass,
hass_client,
entry,
)
assert result["account"] == {
"monitorsCount": 1,
"email": "**REDACTED**",
}
assert result["monitors"] == [
{"id": 1234, "interval": 300, "status": "UP", "type": "HTTP"}
]
assert list(result.keys()) == ["account", "monitors"]
result_dump = json.dumps(result)
assert MOCK_UPTIMEROBOT_EMAIL not in result_dump
assert MOCK_UPTIMEROBOT_API_KEY not in result_dump
async def test_entry_diagnostics_exception(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
) -> None:
"""Test config entry diagnostics with exception."""
entry = await setup_uptimerobot_integration(hass)
with patch(
"pyuptimerobot.UptimeRobot.async_get_account_details",
side_effect=UptimeRobotException("Test exception"),
):
result = await get_diagnostics_for_config_entry(
hass,
hass_client,
entry,
)
assert result["account"] == "Test exception"