Improve test quality in alarm_control_panel
This commit is contained in:
parent
5f68d405b2
commit
a438072e18
2 changed files with 66 additions and 122 deletions
|
@ -1 +1,27 @@
|
||||||
"""The tests for Alarm control panel platforms."""
|
"""The tests for Alarm control panel platforms."""
|
||||||
|
|
||||||
|
from homeassistant.components.alarm_control_panel import (
|
||||||
|
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
|
||||||
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
async def help_async_setup_entry_init(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> bool:
|
||||||
|
"""Set up test config entry."""
|
||||||
|
await hass.config_entries.async_forward_entry_setups(
|
||||||
|
config_entry, [ALARM_CONTROL_PANEL_DOMAIN]
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def help_async_unload_entry(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> bool:
|
||||||
|
"""Unload test config emntry."""
|
||||||
|
return await hass.config_entries.async_unload_platforms(
|
||||||
|
config_entry, [Platform.ALARM_CONTROL_PANEL]
|
||||||
|
)
|
||||||
|
|
|
@ -12,7 +12,6 @@ from homeassistant.components.alarm_control_panel import (
|
||||||
AlarmControlPanelEntityFeature,
|
AlarmControlPanelEntityFeature,
|
||||||
CodeFormat,
|
CodeFormat,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_CODE,
|
ATTR_CODE,
|
||||||
SERVICE_ALARM_ARM_AWAY,
|
SERVICE_ALARM_ARM_AWAY,
|
||||||
|
@ -26,19 +25,18 @@ from homeassistant.const import (
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
||||||
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
||||||
|
|
||||||
from .conftest import TEST_DOMAIN, MockAlarmControlPanel
|
from . import help_async_setup_entry_init, help_async_unload_entry
|
||||||
|
from .conftest import MockAlarmControlPanel
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
MockModule,
|
MockModule,
|
||||||
MockPlatform,
|
|
||||||
help_test_all,
|
help_test_all,
|
||||||
import_and_test_deprecated_constant_enum,
|
import_and_test_deprecated_constant_enum,
|
||||||
mock_integration,
|
mock_integration,
|
||||||
mock_platform,
|
setup_test_component_platform,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,23 +315,6 @@ async def test_alarm_control_panel_log_deprecated_state_warning_using_state_prop
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test incorrectly using state property does log issue and raise repair."""
|
"""Test incorrectly using state property does log issue and raise repair."""
|
||||||
|
|
||||||
async def async_setup_entry_init(
|
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry
|
|
||||||
) -> bool:
|
|
||||||
"""Set up test config entry."""
|
|
||||||
await hass.config_entries.async_forward_entry_setups(
|
|
||||||
config_entry, [ALARM_CONTROL_PANEL_DOMAIN]
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
mock_integration(
|
|
||||||
hass,
|
|
||||||
MockModule(
|
|
||||||
TEST_DOMAIN,
|
|
||||||
async_setup_entry=async_setup_entry_init,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
class MockLegacyAlarmControlPanel(MockAlarmControlPanel):
|
class MockLegacyAlarmControlPanel(MockAlarmControlPanel):
|
||||||
"""Mocked alarm control entity."""
|
"""Mocked alarm control entity."""
|
||||||
|
|
||||||
|
@ -358,30 +339,21 @@ async def test_alarm_control_panel_log_deprecated_state_warning_using_state_prop
|
||||||
code_format=code_format,
|
code_format=code_format,
|
||||||
code_arm_required=code_arm_required,
|
code_arm_required=code_arm_required,
|
||||||
)
|
)
|
||||||
|
config_entry = MockConfigEntry(domain="test")
|
||||||
async def async_setup_entry_platform(
|
config_entry.add_to_hass(hass)
|
||||||
hass: HomeAssistant,
|
mock_integration(
|
||||||
config_entry: ConfigEntry,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
) -> None:
|
|
||||||
"""Set up test alarm control panel platform via config entry."""
|
|
||||||
async_add_entities([entity])
|
|
||||||
|
|
||||||
mock_platform(
|
|
||||||
hass,
|
hass,
|
||||||
f"{TEST_DOMAIN}.{ALARM_CONTROL_PANEL_DOMAIN}",
|
MockModule(
|
||||||
MockPlatform(async_setup_entry=async_setup_entry_platform),
|
"test",
|
||||||
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
|
async_unload_entry=help_async_unload_entry,
|
||||||
|
),
|
||||||
|
built_in=False,
|
||||||
)
|
)
|
||||||
|
setup_test_component_platform(
|
||||||
with patch.object(
|
hass, ALARM_CONTROL_PANEL_DOMAIN, [entity], from_config_entry=True
|
||||||
MockLegacyAlarmControlPanel,
|
)
|
||||||
"__module__",
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
"tests.custom_components.test.alarm_control_panel",
|
|
||||||
):
|
|
||||||
config_entry = MockConfigEntry(domain=TEST_DOMAIN)
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get(entity.entity_id)
|
state = hass.states.get(entity.entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
@ -398,23 +370,6 @@ async def test_alarm_control_panel_log_deprecated_state_warning_using_attr_state
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test incorrectly using _attr_state attribute does log issue and raise repair."""
|
"""Test incorrectly using _attr_state attribute does log issue and raise repair."""
|
||||||
|
|
||||||
async def async_setup_entry_init(
|
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry
|
|
||||||
) -> bool:
|
|
||||||
"""Set up test config entry."""
|
|
||||||
await hass.config_entries.async_forward_entry_setups(
|
|
||||||
config_entry, [ALARM_CONTROL_PANEL_DOMAIN]
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
mock_integration(
|
|
||||||
hass,
|
|
||||||
MockModule(
|
|
||||||
TEST_DOMAIN,
|
|
||||||
async_setup_entry=async_setup_entry_init,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
class MockLegacyAlarmControlPanel(MockAlarmControlPanel):
|
class MockLegacyAlarmControlPanel(MockAlarmControlPanel):
|
||||||
"""Mocked alarm control entity."""
|
"""Mocked alarm control entity."""
|
||||||
|
|
||||||
|
@ -438,30 +393,20 @@ async def test_alarm_control_panel_log_deprecated_state_warning_using_attr_state
|
||||||
code_format=code_format,
|
code_format=code_format,
|
||||||
code_arm_required=code_arm_required,
|
code_arm_required=code_arm_required,
|
||||||
)
|
)
|
||||||
|
config_entry = MockConfigEntry(domain="test")
|
||||||
async def async_setup_entry_platform(
|
config_entry.add_to_hass(hass)
|
||||||
hass: HomeAssistant,
|
mock_integration(
|
||||||
config_entry: ConfigEntry,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
) -> None:
|
|
||||||
"""Set up test alarm control panel platform via config entry."""
|
|
||||||
async_add_entities([entity])
|
|
||||||
|
|
||||||
mock_platform(
|
|
||||||
hass,
|
hass,
|
||||||
f"{TEST_DOMAIN}.{ALARM_CONTROL_PANEL_DOMAIN}",
|
MockModule(
|
||||||
MockPlatform(async_setup_entry=async_setup_entry_platform),
|
"test",
|
||||||
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
|
async_unload_entry=help_async_unload_entry,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
setup_test_component_platform(
|
||||||
with patch.object(
|
hass, ALARM_CONTROL_PANEL_DOMAIN, [entity], from_config_entry=True
|
||||||
MockLegacyAlarmControlPanel,
|
)
|
||||||
"__module__",
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
"tests.custom_components.test.alarm_control_panel",
|
|
||||||
):
|
|
||||||
config_entry = MockConfigEntry(domain=TEST_DOMAIN)
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get(entity.entity_id)
|
state = hass.states.get(entity.entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
@ -500,23 +445,6 @@ async def test_alarm_control_panel_deprecated_state_does_not_break_state(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test using _attr_state attribute does not break state."""
|
"""Test using _attr_state attribute does not break state."""
|
||||||
|
|
||||||
async def async_setup_entry_init(
|
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry
|
|
||||||
) -> bool:
|
|
||||||
"""Set up test config entry."""
|
|
||||||
await hass.config_entries.async_forward_entry_setups(
|
|
||||||
config_entry, [ALARM_CONTROL_PANEL_DOMAIN]
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
mock_integration(
|
|
||||||
hass,
|
|
||||||
MockModule(
|
|
||||||
TEST_DOMAIN,
|
|
||||||
async_setup_entry=async_setup_entry_init,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
class MockLegacyAlarmControlPanel(MockAlarmControlPanel):
|
class MockLegacyAlarmControlPanel(MockAlarmControlPanel):
|
||||||
"""Mocked alarm control entity."""
|
"""Mocked alarm control entity."""
|
||||||
|
|
||||||
|
@ -541,30 +469,20 @@ async def test_alarm_control_panel_deprecated_state_does_not_break_state(
|
||||||
code_format=code_format,
|
code_format=code_format,
|
||||||
code_arm_required=code_arm_required,
|
code_arm_required=code_arm_required,
|
||||||
)
|
)
|
||||||
|
config_entry = MockConfigEntry(domain="test")
|
||||||
async def async_setup_entry_platform(
|
config_entry.add_to_hass(hass)
|
||||||
hass: HomeAssistant,
|
mock_integration(
|
||||||
config_entry: ConfigEntry,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
) -> None:
|
|
||||||
"""Set up test alarm control panel platform via config entry."""
|
|
||||||
async_add_entities([entity])
|
|
||||||
|
|
||||||
mock_platform(
|
|
||||||
hass,
|
hass,
|
||||||
f"{TEST_DOMAIN}.{ALARM_CONTROL_PANEL_DOMAIN}",
|
MockModule(
|
||||||
MockPlatform(async_setup_entry=async_setup_entry_platform),
|
"test",
|
||||||
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
|
async_unload_entry=help_async_unload_entry,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
setup_test_component_platform(
|
||||||
with patch.object(
|
hass, ALARM_CONTROL_PANEL_DOMAIN, [entity], from_config_entry=True
|
||||||
MockLegacyAlarmControlPanel,
|
)
|
||||||
"__module__",
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
"tests.custom_components.test.alarm_control_panel",
|
|
||||||
):
|
|
||||||
config_entry = MockConfigEntry(domain=TEST_DOMAIN)
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get(entity.entity_id)
|
state = hass.states.get(entity.entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
|
Loading…
Add table
Reference in a new issue