Files
hacs_integration/tests/test_diagnostics.py
Joakim Sørensen 5bca567896 Add subentries_data to config entry data if dev (#4445)
* Add subentries_data to config endtry data if dev

* Add config_subentry_id

* josepy<2

* "subentries"

* "subentries"
2025-02-14 08:14:56 +01:00

52 lines
1.5 KiB
Python

"""Test the diagnostics module."""
from custom_components.hacs.base import HacsBase
from custom_components.hacs.diagnostics import async_get_config_entry_diagnostics
from tests.common import (
TOKEN,
MockedResponse,
ResponseMocker,
recursive_remove_key,
safe_json_dumps,
)
from tests.conftest import SnapshotFixture
REMOVE_KEYS = ("entry_id", "last_updated", "local", "minor_version",
"created_at", "modified_at", "discovery_keys", "subentries_data", "subentries")
async def test_diagnostics(hacs: HacsBase, snapshots: SnapshotFixture):
"""Test the base result."""
diagnostics = await async_get_config_entry_diagnostics(
hacs.hass,
hacs.configuration.config_entry,
)
assert TOKEN not in str(diagnostics)
snapshots.assert_match(
safe_json_dumps(recursive_remove_key(
diagnostics, REMOVE_KEYS)), "diagnostics/base.json"
)
async def test_diagnostics_with_exception(
hacs: HacsBase,
snapshots: SnapshotFixture,
response_mocker: ResponseMocker,
):
"""Test the result with issues getting the ratelimit."""
response_mocker.add(
"https://api.github.com/rate_limit",
MockedResponse(status=400, content="Something went wrong"),
)
diagnostics = await async_get_config_entry_diagnostics(
hacs.hass,
hacs.configuration.config_entry,
)
snapshots.assert_match(
safe_json_dumps(recursive_remove_key(diagnostics, REMOVE_KEYS)),
"diagnostics/exception.json",
)