mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve raspberry_pi tests (#73269)
* Improve raspberry_pi tests * Address review comments
This commit is contained in:
parent
542eae1cf3
commit
82afbd1d12
@ -1,6 +1,8 @@
|
|||||||
"""Test the Raspberry Pi integration."""
|
"""Test the Raspberry Pi integration."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.raspberry_pi.const import DOMAIN
|
from homeassistant.components.raspberry_pi.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -8,6 +10,16 @@ from homeassistant.core import HomeAssistant
|
|||||||
from tests.common import MockConfigEntry, MockModule, mock_integration
|
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mock_rpi_power():
|
||||||
|
"""Mock the rpi_power integration."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.rpi_power.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry(hass: HomeAssistant) -> None:
|
async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test setup of a config entry."""
|
"""Test setup of a config entry."""
|
||||||
mock_integration(hass, MockModule("hassio"))
|
mock_integration(hass, MockModule("hassio"))
|
||||||
@ -20,14 +32,19 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
|||||||
title="Raspberry Pi",
|
title="Raspberry Pi",
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert not hass.config_entries.async_entries("rpi_power")
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.raspberry_pi.get_os_info",
|
"homeassistant.components.raspberry_pi.get_os_info",
|
||||||
return_value={"board": "rpi"},
|
return_value={"board": "rpi"},
|
||||||
) as mock_get_os_info:
|
) as mock_get_os_info, patch(
|
||||||
|
"homeassistant.components.rpi_power.config_flow.new_under_voltage"
|
||||||
|
):
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(mock_get_os_info.mock_calls) == 1
|
assert len(mock_get_os_info.mock_calls) == 1
|
||||||
|
|
||||||
|
assert len(hass.config_entries.async_entries("rpi_power")) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
|
async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
|
||||||
"""Test setup of a config entry with wrong board type."""
|
"""Test setup of a config entry with wrong board type."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user