1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00
ha-core/tests/helpers/test_system_info.py
2022-02-04 09:57:14 -08:00

37 lines
1.5 KiB
Python

"""Tests for the system info helper."""
import json
from unittest.mock import patch
from homeassistant.const import __version__ as current_version
async def test_get_system_info(hass):
"""Test the get system info."""
info = await hass.helpers.system_info.async_get_system_info()
assert isinstance(info, dict)
assert info["version"] == current_version
assert info["user"] is not None
assert json.dumps(info) is not None
async def test_container_installationtype(hass):
"""Test container installation type."""
with patch("platform.system", return_value="Linux"), patch(
"os.path.isfile", return_value=True
), patch("homeassistant.helpers.system_info.getuser", return_value="root"):
info = await hass.helpers.system_info.async_get_system_info()
assert info["installation_type"] == "Home Assistant Container"
with patch("platform.system", return_value="Linux"), patch(
"os.path.isfile", side_effect=lambda file: file == "/.dockerenv"
), patch("homeassistant.helpers.system_info.getuser", return_value="user"):
info = await hass.helpers.system_info.async_get_system_info()
assert info["installation_type"] == "Unsupported Third Party Container"
async def test_getuser_keyerror(hass):
"""Test getuser keyerror."""
with patch("homeassistant.helpers.system_info.getuser", side_effect=KeyError):
info = await hass.helpers.system_info.async_get_system_info()
assert info["user"] is None