Add tests for already_configured erros in IronOS integration (#132265)

This commit is contained in:
Manu 2024-12-18 19:33:33 +01:00 committed by GitHub
parent 70ad4ee454
commit 352e948d56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 7 deletions

View File

@ -6,7 +6,7 @@ rules:
appropriate-polling: done
brands: done
common-modules: done
config-flow-test-coverage: todo
config-flow-test-coverage: done
config-flow: done
dependency-transparency: done
docs-actions:

View File

@ -4,6 +4,8 @@ from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock
import pytest
from homeassistant.components.iron_os import DOMAIN
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
from homeassistant.core import HomeAssistant
@ -11,9 +13,12 @@ from homeassistant.data_entry_flow import FlowResultType
from .conftest import DEFAULT_NAME, PINECIL_SERVICE_INFO, USER_INPUT
from tests.common import MockConfigEntry
async def test_form(
hass: HomeAssistant, mock_setup_entry: AsyncMock, discovery: MagicMock
@pytest.mark.usefixtures("discovery")
async def test_async_step_user(
hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test the user config flow."""
result = await hass.config_entries.flow.async_init(
@ -32,10 +37,31 @@ async def test_form(
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.usefixtures("discovery")
async def test_async_step_user_device_added_between_steps(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test the device gets added via another flow between steps."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
USER_INPUT,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
@pytest.mark.usefixtures("mock_setup_entry")
async def test_form_no_device_discovered(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
discovery: MagicMock,
hass: HomeAssistant, discovery: MagicMock
) -> None:
"""Test setup with no device discoveries."""
discovery.return_value = []
@ -48,7 +74,7 @@ async def test_form_no_device_discovered(
async def test_async_step_bluetooth(hass: HomeAssistant) -> None:
"""Test discovery via bluetooth.."""
"""Test discovery via bluetooth."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_BLUETOOTH},
@ -64,3 +90,19 @@ async def test_async_step_bluetooth(hass: HomeAssistant) -> None:
assert result["title"] == DEFAULT_NAME
assert result["data"] == {}
assert result["result"].unique_id == "c0:ff:ee:c0:ff:ee"
async def test_async_step_bluetooth_devices_already_setup(
hass: HomeAssistant, config_entry: AsyncMock
) -> None:
"""Test we can't start a flow if there is already a config entry."""
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_BLUETOOTH},
data=PINECIL_SERVICE_INFO,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"