From d49bccf123f9266f01cf219835d99691f71a0f82 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 Feb 2024 09:09:47 -0600 Subject: [PATCH] Ensure lamarzocco tests add config entry before updating it (#110423) --- tests/components/lamarzocco/__init__.py | 1 - tests/components/lamarzocco/conftest.py | 8 ++++++-- tests/components/lamarzocco/test_config_flow.py | 5 ----- tests/components/lamarzocco/test_init.py | 3 --- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/components/lamarzocco/__init__.py b/tests/components/lamarzocco/__init__.py index bac7d4b3c61..1e7d5ed0148 100644 --- a/tests/components/lamarzocco/__init__.py +++ b/tests/components/lamarzocco/__init__.py @@ -20,6 +20,5 @@ async def async_init_integration( hass: HomeAssistant, mock_config_entry: MockConfigEntry ) -> None: """Set up the La Marzocco integration for testing.""" - mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() diff --git a/tests/components/lamarzocco/conftest.py b/tests/components/lamarzocco/conftest.py index 7bb7e849ef1..68f781407d3 100644 --- a/tests/components/lamarzocco/conftest.py +++ b/tests/components/lamarzocco/conftest.py @@ -20,15 +20,19 @@ from tests.common import ( @pytest.fixture -def mock_config_entry(mock_lamarzocco: MagicMock) -> MockConfigEntry: +def mock_config_entry( + hass: HomeAssistant, mock_lamarzocco: MagicMock +) -> MockConfigEntry: """Return the default mocked config entry.""" - return MockConfigEntry( + entry = MockConfigEntry( title="My LaMarzocco", domain=DOMAIN, data=USER_INPUT | {CONF_MACHINE: mock_lamarzocco.serial_number, CONF_HOST: "host"}, unique_id=mock_lamarzocco.serial_number, ) + entry.add_to_hass(hass) + return entry @pytest.fixture diff --git a/tests/components/lamarzocco/test_config_flow.py b/tests/components/lamarzocco/test_config_flow.py index e8500ee427d..803055ef8ab 100644 --- a/tests/components/lamarzocco/test_config_flow.py +++ b/tests/components/lamarzocco/test_config_flow.py @@ -74,8 +74,6 @@ async def test_form_abort_already_configured( mock_config_entry: MockConfigEntry, ) -> None: """Test we abort if already configured.""" - mock_config_entry.add_to_hass(hass) - result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) @@ -211,9 +209,6 @@ async def test_reauth_flow( hass: HomeAssistant, mock_lamarzocco: MagicMock, mock_config_entry: MockConfigEntry ) -> None: """Test that the reauth flow.""" - - mock_config_entry.add_to_hass(hass) - result = await hass.config_entries.flow.async_init( DOMAIN, context={ diff --git a/tests/components/lamarzocco/test_init.py b/tests/components/lamarzocco/test_init.py index 91243c76eaf..b89ff23b771 100644 --- a/tests/components/lamarzocco/test_init.py +++ b/tests/components/lamarzocco/test_init.py @@ -16,7 +16,6 @@ async def test_load_unload_config_entry( mock_lamarzocco: MagicMock, ) -> None: """Test loading and unloading the integration.""" - mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() @@ -36,7 +35,6 @@ async def test_config_entry_not_ready( """Test the La Marzocco configuration entry not ready.""" mock_lamarzocco.update_local_machine_status.side_effect = RequestNotSuccessful("") - mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() @@ -51,7 +49,6 @@ async def test_invalid_auth( ) -> None: """Test auth error during setup.""" mock_lamarzocco.update_local_machine_status.side_effect = AuthFail("") - mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done()