Skip to content

Commit

Permalink
Add tests for already_configured erros in IronOS integration (home-as…
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r authored Dec 18, 2024
1 parent 70ad4ee commit 352e948
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/iron_os/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
54 changes: 48 additions & 6 deletions tests/components/iron_os/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

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
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(
Expand All @@ -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 = []
Expand All @@ -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},
Expand All @@ -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"

0 comments on commit 352e948

Please sign in to comment.