Fix BleBox config flow tests opening sockets (#184022)

This commit is contained in:
bkobus-bbx
2026-10-02 22:38:07 +02:00
committed by GitHub
parent b3e7509feb
commit c5c10f0537
2 changed files with 36 additions and 3 deletions
+10
View File
@@ -1,5 +1,6 @@
"""PyTest fixtures and test helpers."""
from collections.abc import Generator
from typing import Any
from unittest import mock
from unittest.mock import AsyncMock, PropertyMock, patch
@@ -101,6 +102,15 @@ def config_entry_fixture() -> MockConfigEntry:
return mock_config()
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry."""
with patch(
"homeassistant.components.blebox.async_setup_entry", return_value=True
) as mock_setup:
yield mock_setup
@pytest.fixture(name="config")
def config_fixture():
"""Create hass config fixture."""
+26 -3
View File
@@ -382,7 +382,10 @@ def create_product_mock(unique_id: str = "abcd0123ef5678"):
async def test_reconfigure_flow_works(
hass: HomeAssistant, config_entry: MockConfigEntry, product_class_mock
hass: HomeAssistant,
config_entry: MockConfigEntry,
product_class_mock,
mock_setup_entry: AsyncMock,
) -> None:
"""Test that reconfigure flow updates host and port."""
@@ -406,12 +409,15 @@ async def test_reconfigure_flow_works(
},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
assert config_entry.data[config_flow.CONF_HOST] == "172.2.3.5"
assert config_entry.data[config_flow.CONF_PORT] == 80
assert config_entry.data[config_flow.CONF_USERNAME] == "admin"
assert config_entry.data[config_flow.CONF_PASSWORD] == "secret"
assert len(mock_setup_entry.mock_calls) == 1
async def test_reconfigure_flow_unique_id_mismatch(
@@ -548,6 +554,7 @@ async def test_reconfigure_flow_recovers_after_error(
hass: HomeAssistant,
config_entry: MockConfigEntry,
product_class_mock,
mock_setup_entry: AsyncMock,
exception: type[Exception],
expected_error: str,
) -> None:
@@ -576,12 +583,18 @@ async def test_reconfigure_flow_recovers_after_error(
{config_flow.CONF_HOST: "172.2.3.5", config_flow.CONF_PORT: 80},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
assert len(mock_setup_entry.mock_calls) == 1
async def test_reauth_flow_works(
hass: HomeAssistant, config_entry: MockConfigEntry, product_class_mock
hass: HomeAssistant,
config_entry: MockConfigEntry,
product_class_mock,
mock_setup_entry: AsyncMock,
) -> None:
"""Test that reauth flow updates credentials and reloads."""
config_entry.add_to_hass(hass)
@@ -599,14 +612,17 @@ async def test_reauth_flow_works(
{config_flow.CONF_USERNAME: "admin", config_flow.CONF_PASSWORD: "secret"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert config_entry.data[config_flow.CONF_USERNAME] == "admin"
assert config_entry.data[config_flow.CONF_PASSWORD] == "secret"
assert len(mock_setup_entry.mock_calls) == 1
async def test_reauth_flow_works_without_credentials(
hass: HomeAssistant, product_class_mock
hass: HomeAssistant, product_class_mock, mock_setup_entry: AsyncMock
) -> None:
"""Test that reauth flow clears credentials when submitted without them."""
config_entry = MockConfigEntry(
@@ -632,10 +648,13 @@ async def test_reauth_flow_works_without_credentials(
{},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert config_entry.data[config_flow.CONF_USERNAME] is None
assert config_entry.data[config_flow.CONF_PASSWORD] is None
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.parametrize(
@@ -652,6 +671,7 @@ async def test_reauth_flow_recovers_after_error(
hass: HomeAssistant,
config_entry: MockConfigEntry,
product_class_mock,
mock_setup_entry: AsyncMock,
exception: type[Exception],
expected_error: str,
) -> None:
@@ -680,5 +700,8 @@ async def test_reauth_flow_recovers_after_error(
{config_flow.CONF_USERNAME: "admin", config_flow.CONF_PASSWORD: "secret"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert len(mock_setup_entry.mock_calls) == 1