core/tests/components/netatmo/test_diagnostics.py

56 lines
1.7 KiB
Python

"""Test the Netatmo diagnostics."""
from functools import partial
from unittest.mock import AsyncMock, patch
from syrupy.assertion import SnapshotAssertion
from syrupy.filters import paths
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .common import fake_post_request
from tests.common import MockConfigEntry
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,
snapshot: SnapshotAssertion,
config_entry: MockConfigEntry,
) -> None:
"""Test config entry diagnostics."""
with (
patch(
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth",
) as mock_auth,
patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
),
patch(
"homeassistant.components.netatmo.webhook_generate_url",
),
):
mock_auth.return_value.async_post_api_request.side_effect = partial(
fake_post_request, hass
)
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
mock_auth.return_value.async_dropwebhook.side_effect = AsyncMock()
assert await async_setup_component(hass, "netatmo", {})
await hass.async_block_till_done()
assert await get_diagnostics_for_config_entry(
hass, hass_client, config_entry
) == snapshot(
exclude=paths(
"info.data.token.expires_at",
"info.entry_id",
"info.created_at",
"info.modified_at",
)
)