-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add system health tests * Update snapshots
- Loading branch information
1 parent
338aaab
commit 5de7986
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"Available Repositories": 7, | ||
"Downloaded Repositories": 1, | ||
"GitHub API": "ok", | ||
"GitHub API Calls Remaining": 4999, | ||
"GitHub Content": "ok", | ||
"GitHub Web": "ok", | ||
"HACS Data": "ok", | ||
"Installed Version": "0.0.0", | ||
"Stage": "running" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Test system health.""" | ||
|
||
import asyncio | ||
from typing import Any, Generator | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.setup import async_setup_component | ||
import pytest | ||
|
||
from custom_components.hacs.base import HacsBase | ||
|
||
from tests.common import MockedResponse, ResponseMocker, safe_json_dumps | ||
from tests.conftest import SnapshotFixture | ||
|
||
|
||
HACS_SYSTEM_HEALTH_DOMAIN = "Home Assistant Community Store" | ||
|
||
|
||
async def get_system_health_info(hass: HomeAssistant, domain: str) -> dict[str, Any]: | ||
"""Get system health info.""" | ||
return await hass.data["system_health"][domain].info_callback(hass) | ||
|
||
|
||
async def test_system_health( | ||
setup_integration: Generator, | ||
hass: HomeAssistant, | ||
response_mocker: ResponseMocker, | ||
snapshots: SnapshotFixture, | ||
) -> None: | ||
"""Test HACS system health.""" | ||
response_mocker.add( | ||
url="https://api.github.com", | ||
response=MockedResponse( | ||
content={}, | ||
headers={"Content-Type": "application/json"}, | ||
), | ||
) | ||
response_mocker.add( | ||
url="https://raw.githubusercontent.com/hacs/integration/main/hacs.json", | ||
response=MockedResponse( | ||
content={}, | ||
headers={"Content-Type": "application/json"}, | ||
), | ||
) | ||
response_mocker.add( | ||
url="https://data-v2.hacs.xyz/data.json", | ||
response=MockedResponse( | ||
content={}, | ||
headers={"Content-Type": "application/json"}, | ||
), | ||
) | ||
|
||
assert await async_setup_component(hass, "system_health", {}) | ||
await hass.async_block_till_done() | ||
|
||
info = await get_system_health_info(hass, HACS_SYSTEM_HEALTH_DOMAIN) | ||
|
||
for key, val in info.items(): | ||
if asyncio.iscoroutine(val): | ||
info[key] = await val | ||
|
||
snapshots.assert_match(safe_json_dumps(info), "system_health/system_health.json") | ||
|
||
|
||
async def test_system_health_after_unload( | ||
hacs: HacsBase, | ||
hass: HomeAssistant, | ||
) -> None: | ||
"""Test HACS system health.""" | ||
await hass.config_entries.async_unload(hacs.configuration.config_entry.entry_id) | ||
|
||
assert await async_setup_component(hass, "system_health", {}) | ||
await hass.async_block_till_done() | ||
|
||
with pytest.raises(KeyError, match="hacs"): | ||
await get_system_health_info(hass, HACS_SYSTEM_HEALTH_DOMAIN) | ||
|
||
|
||
async def test_system_health_no_hacs( | ||
hass: HomeAssistant, | ||
) -> None: | ||
"""Test HACS system health.""" | ||
assert await async_setup_component(hass, "system_health", {}) | ||
await hass.async_block_till_done() | ||
|
||
with pytest.raises(KeyError, match=HACS_SYSTEM_HEALTH_DOMAIN): | ||
await get_system_health_info(hass, HACS_SYSTEM_HEALTH_DOMAIN) |