Improve UniFi config flow tests (#118587)

* Use proper fixtures in config flow tests

* Improve rest of config flow tests

* Small improvement

* Rename fixtures
This commit is contained in:
Robert Svensson 2024-06-01 00:27:53 +02:00 committed by GitHub
parent 738935a73a
commit 3232fd0eaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 105 additions and 216 deletions

View file

@ -35,20 +35,20 @@ async def test_setup_with_no_config(hass: HomeAssistant) -> None:
async def test_setup_entry_fails_config_entry_not_ready(
hass: HomeAssistant, prepare_config_entry: Callable[[], ConfigEntry]
hass: HomeAssistant, config_entry_factory: Callable[[], ConfigEntry]
) -> None:
"""Failed authentication trigger a reauthentication flow."""
with patch(
"homeassistant.components.unifi.get_unifi_api",
side_effect=CannotConnect,
):
config_entry = await prepare_config_entry()
config_entry = await config_entry_factory()
assert config_entry.state == ConfigEntryState.SETUP_RETRY
async def test_setup_entry_fails_trigger_reauth_flow(
hass: HomeAssistant, prepare_config_entry: Callable[[], ConfigEntry]
hass: HomeAssistant, config_entry_factory: Callable[[], ConfigEntry]
) -> None:
"""Failed authentication trigger a reauthentication flow."""
with (
@ -58,7 +58,7 @@ async def test_setup_entry_fails_trigger_reauth_flow(
),
patch.object(hass.config_entries.flow, "async_init") as mock_flow_init,
):
config_entry = await prepare_config_entry()
config_entry = await config_entry_factory()
mock_flow_init.assert_called_once()
assert config_entry.state == ConfigEntryState.SETUP_ERROR
@ -86,7 +86,7 @@ async def test_setup_entry_fails_trigger_reauth_flow(
async def test_wireless_clients(
hass: HomeAssistant,
hass_storage: dict[str, Any],
prepare_config_entry: Callable[[], ConfigEntry],
config_entry_factory: Callable[[], ConfigEntry],
) -> None:
"""Verify wireless clients class."""
hass_storage[unifi.STORAGE_KEY] = {
@ -98,7 +98,7 @@ async def test_wireless_clients(
},
}
await prepare_config_entry()
await config_entry_factory()
await flush_store(hass.data[unifi.UNIFI_WIRELESS_CLIENTS]._store)
assert sorted(hass_storage[unifi.STORAGE_KEY]["data"]["wireless_clients"]) == [
@ -173,14 +173,14 @@ async def test_remove_config_entry_device(
hass_storage: dict[str, Any],
aioclient_mock: AiohttpClientMocker,
device_registry: dr.DeviceRegistry,
prepare_config_entry: Callable[[], ConfigEntry],
config_entry_factory: Callable[[], ConfigEntry],
client_payload: list[dict[str, Any]],
device_payload: list[dict[str, Any]],
mock_unifi_websocket,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Verify removing a device manually."""
config_entry = await prepare_config_entry()
config_entry = await config_entry_factory()
assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass)