From c5c10f0537852fcaaf50bae6b1d74e0431e07ce7 Mon Sep 17 00:00:00 2001 From: bkobus-bbx Date: Fri, 2 Oct 2026 22:38:07 +0200 Subject: [PATCH] Fix BleBox config flow tests opening sockets (#184022) --- tests/components/blebox/conftest.py | 10 +++++++ tests/components/blebox/test_config_flow.py | 29 ++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/components/blebox/conftest.py b/tests/components/blebox/conftest.py index 3af11c4c0485..0096017a38ed 100644 --- a/tests/components/blebox/conftest.py +++ b/tests/components/blebox/conftest.py @@ -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.""" diff --git a/tests/components/blebox/test_config_flow.py b/tests/components/blebox/test_config_flow.py index 55da9401749c..2792eeaf244e 100644 --- a/tests/components/blebox/test_config_flow.py +++ b/tests/components/blebox/test_config_flow.py @@ -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