mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
TotalConnect refactor tests (#140240)
* refactor button * refactor test_options_flow
This commit is contained in:
parent
593ae48aa2
commit
2f1ff5ab95
@ -11,12 +11,7 @@ from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import (
|
||||
RESPONSE_ZONE_BYPASS_FAILURE,
|
||||
RESPONSE_ZONE_BYPASS_SUCCESS,
|
||||
TOTALCONNECT_REQUEST,
|
||||
setup_platform,
|
||||
)
|
||||
from .common import setup_platform
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
@ -34,12 +29,23 @@ async def test_entity_registry(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entity_id", [ZONE_BYPASS_ID, PANEL_BYPASS_ID])
|
||||
async def test_bypass_button(hass: HomeAssistant, entity_id: str) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "tcc_request"),
|
||||
[
|
||||
(ZONE_BYPASS_ID, "total_connect_client.zone.TotalConnectZone.bypass"),
|
||||
(
|
||||
PANEL_BYPASS_ID,
|
||||
"total_connect_client.location.TotalConnectLocation.zone_bypass_all",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_bypass_button(
|
||||
hass: HomeAssistant, entity_id: str, tcc_request: str
|
||||
) -> None:
|
||||
"""Test pushing a bypass button."""
|
||||
responses = [RESPONSE_ZONE_BYPASS_FAILURE, RESPONSE_ZONE_BYPASS_SUCCESS]
|
||||
responses = [FailedToBypassZone, None]
|
||||
await setup_platform(hass, BUTTON)
|
||||
with patch(TOTALCONNECT_REQUEST, side_effect=responses) as mock_request:
|
||||
with patch(tcc_request, side_effect=responses) as mock_request:
|
||||
# try to bypass, but fails
|
||||
with pytest.raises(FailedToBypassZone):
|
||||
await hass.services.async_call(
|
||||
|
@ -28,6 +28,7 @@ from .common import (
|
||||
TOTALCONNECT_REQUEST,
|
||||
TOTALCONNECT_REQUEST_TOKEN,
|
||||
USERNAME,
|
||||
init_integration,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -219,42 +220,19 @@ async def test_no_locations(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_options_flow(hass: HomeAssistant) -> None:
|
||||
"""Test config flow options."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=CONFIG_DATA,
|
||||
unique_id=USERNAME,
|
||||
config_entry = await init_integration(hass)
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={AUTO_BYPASS: True, CODE_REQUIRED: False}
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
responses = [
|
||||
RESPONSE_SESSION_DETAILS,
|
||||
RESPONSE_PARTITION_DETAILS,
|
||||
RESPONSE_GET_ZONE_DETAILS_SUCCESS,
|
||||
RESPONSE_DISARMED,
|
||||
RESPONSE_DISARMED,
|
||||
RESPONSE_DISARMED,
|
||||
]
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert config_entry.options == {AUTO_BYPASS: True, CODE_REQUIRED: False}
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with (
|
||||
patch(TOTALCONNECT_REQUEST, side_effect=responses),
|
||||
patch(TOTALCONNECT_GET_CONFIG, side_effect=None),
|
||||
patch(TOTALCONNECT_REQUEST_TOKEN, side_effect=None),
|
||||
):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={AUTO_BYPASS: True, CODE_REQUIRED: False}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert config_entry.options == {AUTO_BYPASS: True, CODE_REQUIRED: False}
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user