mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add hardkernel hardware integration (#72489)
* Add hardkernel hardware integration * Remove debug prints * Improve tests * Improve test coverage
This commit is contained in:
58
tests/components/hardkernel/test_config_flow.py
Normal file
58
tests/components/hardkernel/test_config_flow.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Test the Hardkernel config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.hardkernel.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import RESULT_TYPE_ABORT, RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||
|
||||
|
||||
async def test_config_flow(hass: HomeAssistant) -> None:
|
||||
"""Test the config flow."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.hardkernel.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "system"}
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "Hardkernel"
|
||||
assert result["data"] == {}
|
||||
assert result["options"] == {}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
assert config_entry.data == {}
|
||||
assert config_entry.options == {}
|
||||
assert config_entry.title == "Hardkernel"
|
||||
|
||||
|
||||
async def test_config_flow_single_entry(hass: HomeAssistant) -> None:
|
||||
"""Test only a single entry is allowed."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
data={},
|
||||
domain=DOMAIN,
|
||||
options={},
|
||||
title="Hardkernel",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.hardkernel.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "system"}
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "single_instance_allowed"
|
||||
mock_setup_entry.assert_not_called()
|
||||
Reference in New Issue
Block a user