Add type hints to helper tests (#89784)
This commit is contained in:
parent
69e85b3216
commit
46a5aa71ec
5 changed files with 97 additions and 39 deletions
|
@ -1,4 +1,5 @@
|
|||
"""Tests for the Config Entry Flow helper."""
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import Mock, PropertyMock, patch
|
||||
|
||||
import pytest
|
||||
|
@ -17,11 +18,11 @@ from tests.common import (
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def discovery_flow_conf(hass):
|
||||
def discovery_flow_conf(hass: HomeAssistant) -> Generator[dict[str, bool], None, None]:
|
||||
"""Register a handler."""
|
||||
handler_conf = {"discovered": False}
|
||||
|
||||
async def has_discovered_devices(hass):
|
||||
async def has_discovered_devices(hass: HomeAssistant) -> bool:
|
||||
"""Mock if we have discovered devices."""
|
||||
return handler_conf["discovered"]
|
||||
|
||||
|
@ -33,17 +34,19 @@ def discovery_flow_conf(hass):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def webhook_flow_conf(hass):
|
||||
def webhook_flow_conf(hass: HomeAssistant) -> Generator[None, None, None]:
|
||||
"""Register a handler."""
|
||||
with patch.dict(config_entries.HANDLERS):
|
||||
config_entry_flow.register_webhook_flow("test_single", "Test Single", {}, False)
|
||||
config_entry_flow.register_webhook_flow(
|
||||
"test_multiple", "Test Multiple", {}, True
|
||||
)
|
||||
yield {}
|
||||
yield
|
||||
|
||||
|
||||
async def test_single_entry_allowed(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_single_entry_allowed(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test only a single entry is allowed."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
flow.hass = hass
|
||||
|
@ -56,7 +59,9 @@ async def test_single_entry_allowed(hass: HomeAssistant, discovery_flow_conf) ->
|
|||
assert result["reason"] == "single_instance_allowed"
|
||||
|
||||
|
||||
async def test_user_no_devices_found(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_user_no_devices_found(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test if no devices found."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
flow.hass = hass
|
||||
|
@ -67,7 +72,9 @@ async def test_user_no_devices_found(hass: HomeAssistant, discovery_flow_conf) -
|
|||
assert result["reason"] == "no_devices_found"
|
||||
|
||||
|
||||
async def test_user_has_confirmation(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_user_has_confirmation(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test user requires confirmation to setup."""
|
||||
discovery_flow_conf["discovered"] = True
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
@ -104,7 +111,7 @@ async def test_user_has_confirmation(hass: HomeAssistant, discovery_flow_conf) -
|
|||
],
|
||||
)
|
||||
async def test_discovery_single_instance(
|
||||
hass: HomeAssistant, discovery_flow_conf, source
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool], source: str
|
||||
) -> None:
|
||||
"""Test we not allow duplicates."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
|
@ -130,7 +137,7 @@ async def test_discovery_single_instance(
|
|||
],
|
||||
)
|
||||
async def test_discovery_confirmation(
|
||||
hass: HomeAssistant, discovery_flow_conf, source
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool], source: str
|
||||
) -> None:
|
||||
"""Test we ask for confirmation via discovery."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
|
@ -158,7 +165,7 @@ async def test_discovery_confirmation(
|
|||
],
|
||||
)
|
||||
async def test_discovery_during_onboarding(
|
||||
hass: HomeAssistant, discovery_flow_conf, source
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool], source: str
|
||||
) -> None:
|
||||
"""Test we create config entry via discovery during onboarding."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
|
@ -173,7 +180,9 @@ async def test_discovery_during_onboarding(
|
|||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_multiple_discoveries(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_multiple_discoveries(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test we only create one instance for multiple discoveries."""
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
|
@ -189,7 +198,9 @@ async def test_multiple_discoveries(hass: HomeAssistant, discovery_flow_conf) ->
|
|||
assert result["type"] == data_entry_flow.FlowResultType.ABORT
|
||||
|
||||
|
||||
async def test_only_one_in_progress(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_only_one_in_progress(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test a user initialized one will finish and cancel discovered one."""
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
|
@ -215,7 +226,9 @@ async def test_only_one_in_progress(hass: HomeAssistant, discovery_flow_conf) ->
|
|||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
|
||||
async def test_import_abort_discovery(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_import_abort_discovery(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test import will finish and cancel discovered one."""
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
|
@ -236,7 +249,9 @@ async def test_import_abort_discovery(hass: HomeAssistant, discovery_flow_conf)
|
|||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
|
||||
async def test_import_no_confirmation(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_import_no_confirmation(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test import requires no confirmation to set up."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
flow.hass = hass
|
||||
|
@ -247,7 +262,9 @@ async def test_import_no_confirmation(hass: HomeAssistant, discovery_flow_conf)
|
|||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_import_single_instance(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_import_single_instance(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test import doesn't create second instance."""
|
||||
flow = config_entries.HANDLERS["test"]()
|
||||
flow.hass = hass
|
||||
|
@ -259,7 +276,9 @@ async def test_import_single_instance(hass: HomeAssistant, discovery_flow_conf)
|
|||
assert result["type"] == data_entry_flow.FlowResultType.ABORT
|
||||
|
||||
|
||||
async def test_ignored_discoveries(hass: HomeAssistant, discovery_flow_conf) -> None:
|
||||
async def test_ignored_discoveries(
|
||||
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
|
||||
) -> None:
|
||||
"""Test we can ignore discovered entries."""
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
|
@ -292,7 +311,7 @@ async def test_ignored_discoveries(hass: HomeAssistant, discovery_flow_conf) ->
|
|||
|
||||
|
||||
async def test_webhook_single_entry_allowed(
|
||||
hass: HomeAssistant, webhook_flow_conf
|
||||
hass: HomeAssistant, webhook_flow_conf: None
|
||||
) -> None:
|
||||
"""Test only a single entry is allowed."""
|
||||
flow = config_entries.HANDLERS["test_single"]()
|
||||
|
@ -306,7 +325,7 @@ async def test_webhook_single_entry_allowed(
|
|||
|
||||
|
||||
async def test_webhook_multiple_entries_allowed(
|
||||
hass: HomeAssistant, webhook_flow_conf
|
||||
hass: HomeAssistant, webhook_flow_conf: None
|
||||
) -> None:
|
||||
"""Test multiple entries are allowed when specified."""
|
||||
flow = config_entries.HANDLERS["test_multiple"]()
|
||||
|
@ -320,7 +339,7 @@ async def test_webhook_multiple_entries_allowed(
|
|||
|
||||
|
||||
async def test_webhook_config_flow_registers_webhook(
|
||||
hass: HomeAssistant, webhook_flow_conf
|
||||
hass: HomeAssistant, webhook_flow_conf: None
|
||||
) -> None:
|
||||
"""Test setting up an entry creates a webhook."""
|
||||
flow = config_entries.HANDLERS["test_single"]()
|
||||
|
@ -336,7 +355,9 @@ async def test_webhook_config_flow_registers_webhook(
|
|||
assert result["data"]["webhook_id"] is not None
|
||||
|
||||
|
||||
async def test_webhook_create_cloudhook(hass: HomeAssistant, webhook_flow_conf) -> None:
|
||||
async def test_webhook_create_cloudhook(
|
||||
hass: HomeAssistant, webhook_flow_conf: None
|
||||
) -> None:
|
||||
"""Test cloudhook will be created if subscribed."""
|
||||
assert await setup.async_setup_component(hass, "cloud", {})
|
||||
|
||||
|
@ -390,7 +411,7 @@ async def test_webhook_create_cloudhook(hass: HomeAssistant, webhook_flow_conf)
|
|||
|
||||
|
||||
async def test_webhook_create_cloudhook_aborts_not_connected(
|
||||
hass: HomeAssistant, webhook_flow_conf
|
||||
hass: HomeAssistant, webhook_flow_conf: None
|
||||
) -> None:
|
||||
"""Test cloudhook aborts if subscribed but not connected."""
|
||||
assert await setup.async_setup_component(hass, "cloud", {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue