mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +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.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .common import (
|
from .common import setup_platform
|
||||||
RESPONSE_ZONE_BYPASS_FAILURE,
|
|
||||||
RESPONSE_ZONE_BYPASS_SUCCESS,
|
|
||||||
TOTALCONNECT_REQUEST,
|
|
||||||
setup_platform,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.common import snapshot_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)
|
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("entity_id", [ZONE_BYPASS_ID, PANEL_BYPASS_ID])
|
@pytest.mark.parametrize(
|
||||||
async def test_bypass_button(hass: HomeAssistant, entity_id: str) -> None:
|
("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."""
|
"""Test pushing a bypass button."""
|
||||||
responses = [RESPONSE_ZONE_BYPASS_FAILURE, RESPONSE_ZONE_BYPASS_SUCCESS]
|
responses = [FailedToBypassZone, None]
|
||||||
await setup_platform(hass, BUTTON)
|
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
|
# try to bypass, but fails
|
||||||
with pytest.raises(FailedToBypassZone):
|
with pytest.raises(FailedToBypassZone):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
|
@ -28,6 +28,7 @@ from .common import (
|
|||||||
TOTALCONNECT_REQUEST,
|
TOTALCONNECT_REQUEST,
|
||||||
TOTALCONNECT_REQUEST_TOKEN,
|
TOTALCONNECT_REQUEST_TOKEN,
|
||||||
USERNAME,
|
USERNAME,
|
||||||
|
init_integration,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
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:
|
async def test_options_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = await init_integration(hass)
|
||||||
domain=DOMAIN,
|
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||||
data=CONFIG_DATA,
|
|
||||||
unique_id=USERNAME,
|
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 = [
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
RESPONSE_SESSION_DETAILS,
|
assert config_entry.options == {AUTO_BYPASS: True, CODE_REQUIRED: False}
|
||||||
RESPONSE_PARTITION_DETAILS,
|
await hass.async_block_till_done()
|
||||||
RESPONSE_GET_ZONE_DETAILS_SUCCESS,
|
|
||||||
RESPONSE_DISARMED,
|
|
||||||
RESPONSE_DISARMED,
|
|
||||||
RESPONSE_DISARMED,
|
|
||||||
]
|
|
||||||
|
|
||||||
with (
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
patch(TOTALCONNECT_REQUEST, side_effect=responses),
|
await hass.async_block_till_done()
|
||||||
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()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user