Improve raspberry_pi tests (#72557)
parent
828fcd0a48
commit
d1578aacf2
|
@ -1,23 +1,39 @@
|
||||||
"""Test the Raspberry Pi hardware platform."""
|
"""Test the Raspberry Pi hardware platform."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.hassio import DATA_OS_INFO
|
|
||||||
from homeassistant.components.raspberry_pi.const import DOMAIN
|
from homeassistant.components.raspberry_pi.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockModule, mock_integration
|
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||||
|
|
||||||
|
|
||||||
async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None:
|
async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None:
|
||||||
"""Test we can get the board info."""
|
"""Test we can get the board info."""
|
||||||
mock_integration(hass, MockModule("hassio"))
|
mock_integration(hass, MockModule("hassio"))
|
||||||
hass.data[DATA_OS_INFO] = {"board": "rpi"}
|
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {})
|
# Setup the config entry
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
data={},
|
||||||
|
domain=DOMAIN,
|
||||||
|
options={},
|
||||||
|
title="Raspberry Pi",
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.raspberry_pi.get_os_info",
|
||||||
|
return_value={"board": "rpi"},
|
||||||
|
):
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
client = await hass_ws_client(hass)
|
client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.raspberry_pi.hardware.get_os_info",
|
||||||
|
return_value={"board": "rpi"},
|
||||||
|
):
|
||||||
await client.send_json({"id": 1, "type": "hardware/info"})
|
await client.send_json({"id": 1, "type": "hardware/info"})
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
|
|
||||||
|
@ -43,12 +59,28 @@ async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None:
|
||||||
async def test_hardware_info_fail(hass: HomeAssistant, hass_ws_client, os_info) -> None:
|
async def test_hardware_info_fail(hass: HomeAssistant, hass_ws_client, os_info) -> None:
|
||||||
"""Test async_info raises if os_info is not as expected."""
|
"""Test async_info raises if os_info is not as expected."""
|
||||||
mock_integration(hass, MockModule("hassio"))
|
mock_integration(hass, MockModule("hassio"))
|
||||||
hass.data[DATA_OS_INFO] = os_info
|
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {})
|
# Setup the config entry
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
data={},
|
||||||
|
domain=DOMAIN,
|
||||||
|
options={},
|
||||||
|
title="Raspberry Pi",
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.raspberry_pi.get_os_info",
|
||||||
|
return_value={"board": "rpi"},
|
||||||
|
):
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
client = await hass_ws_client(hass)
|
client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.raspberry_pi.hardware.get_os_info",
|
||||||
|
return_value=os_info,
|
||||||
|
):
|
||||||
await client.send_json({"id": 1, "type": "hardware/info"})
|
await client.send_json({"id": 1, "type": "hardware/info"})
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue