From 261f9c5d624c8b90b5633b2a48871183bce0166a Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Thu, 8 Feb 2024 19:52:40 -0800 Subject: [PATCH] Cleanup test config entry setup to use best practices (#110070) * Cleanup test config entry setup to use best practices * Add missed files --- tests/components/caldav/test_calendar.py | 4 ++-- tests/components/caldav/test_init.py | 4 ++-- tests/components/caldav/test_todo.py | 24 +++++++++---------- .../components/rainbird/test_binary_sensor.py | 4 ++-- tests/components/rainbird/test_calendar.py | 6 ++--- tests/components/rainbird/test_config_flow.py | 4 ++-- tests/components/rainbird/test_number.py | 4 ++-- tests/components/rainbird/test_sensor.py | 4 ++-- tests/components/rainbird/test_switch.py | 4 ++-- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/components/caldav/test_calendar.py b/tests/components/caldav/test_calendar.py index df5428121ee..11f1524b4b0 100644 --- a/tests/components/caldav/test_calendar.py +++ b/tests/components/caldav/test_calendar.py @@ -1090,7 +1090,7 @@ async def test_setup_config_entry( ) -> None: """Test a calendar entity from a config entry.""" config_entry.add_to_hass(hass) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get(TEST_ENTITY) assert state @@ -1124,7 +1124,7 @@ async def test_config_entry_supported_components( ) -> None: """Test that calendars are only created for VEVENT types when using a config entry.""" config_entry.add_to_hass(hass) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get("calendar.calendar_1") assert state diff --git a/tests/components/caldav/test_init.py b/tests/components/caldav/test_init.py index 8e832e24d2d..192c18ef81a 100644 --- a/tests/components/caldav/test_init.py +++ b/tests/components/caldav/test_init.py @@ -26,7 +26,7 @@ async def test_load_unload( assert config_entry.state == ConfigEntryState.NOT_LOADED with patch("homeassistant.components.caldav.config_flow.caldav.DAVClient"): - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED @@ -63,7 +63,7 @@ async def test_client_failure( "homeassistant.components.caldav.config_flow.caldav.DAVClient" ) as mock_client: mock_client.return_value.principal.side_effect = side_effect - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state == expected_state diff --git a/tests/components/caldav/test_todo.py b/tests/components/caldav/test_todo.py index 6056cac5fa9..7b67a1af714 100644 --- a/tests/components/caldav/test_todo.py +++ b/tests/components/caldav/test_todo.py @@ -188,7 +188,7 @@ async def test_todo_list_state( expected_state: str, ) -> None: """Test a calendar entity from a config entry.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get(TEST_ENTITY) assert state @@ -210,7 +210,7 @@ async def test_supported_components( has_entity: bool, ) -> None: """Test a calendar supported components matches VTODO.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get(TEST_ENTITY) assert (state is not None) == has_entity @@ -266,7 +266,7 @@ async def test_add_item( ) -> None: """Test adding an item to the list.""" calendar.search.return_value = [] - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get(TEST_ENTITY) assert state @@ -298,7 +298,7 @@ async def test_add_item_failure( calendar: Mock, ) -> None: """Test failure when adding an item to the list.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) calendar.save_todo.side_effect = DAVError() @@ -488,7 +488,7 @@ async def test_update_item( item = Todo(dav_client, None, TODO_ALL_FIELDS, calendar, "2") calendar.search = MagicMock(return_value=[item]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get(TEST_ENTITY) assert state @@ -539,7 +539,7 @@ async def test_update_item_failure( item = Todo(dav_client, None, TODO_NEEDS_ACTION, calendar, "2") calendar.search = MagicMock(return_value=[item]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) calendar.todo_by_uid = MagicMock(return_value=item) dav_client.put.side_effect = DAVError() @@ -574,7 +574,7 @@ async def test_update_item_lookup_failure( item = Todo(dav_client, None, TODO_NEEDS_ACTION, calendar, "2") calendar.search = MagicMock(return_value=[item]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) calendar.todo_by_uid.side_effect = side_effect @@ -616,7 +616,7 @@ async def test_remove_item( item2 = Todo(dav_client, None, TODO_COMPLETED, calendar, "3") calendar.search = MagicMock(return_value=[item1, item2]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) state = hass.states.get(TEST_ENTITY) assert state @@ -660,7 +660,7 @@ async def test_remove_item_lookup_failure( ) -> None: """Test failure while removing an item from the list.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) calendar.todo_by_uid.side_effect = side_effect @@ -685,7 +685,7 @@ async def test_remove_item_failure( item = Todo(dav_client, "2.ics", TODO_NEEDS_ACTION, calendar, "2") calendar.search = MagicMock(return_value=[item]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) def lookup(uid: str) -> Mock: return item @@ -714,7 +714,7 @@ async def test_remove_item_not_found( item = Todo(dav_client, "2.ics", TODO_NEEDS_ACTION, calendar, "2") calendar.search = MagicMock(return_value=[item]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) def lookup(uid: str) -> Mock: return item @@ -743,7 +743,7 @@ async def test_subscribe( item = Todo(dav_client, None, TODO_NEEDS_ACTION, calendar, "2") calendar.search = MagicMock(return_value=[item]) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) # Subscribe and get the initial list client = await hass_ws_client(hass) diff --git a/tests/components/rainbird/test_binary_sensor.py b/tests/components/rainbird/test_binary_sensor.py index afe18337377..826a7635c53 100644 --- a/tests/components/rainbird/test_binary_sensor.py +++ b/tests/components/rainbird/test_binary_sensor.py @@ -32,7 +32,7 @@ async def setup_config_entry( hass: HomeAssistant, config_entry: MockConfigEntry ) -> list[Platform]: """Fixture to setup the config entry.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED @@ -74,7 +74,7 @@ async def test_no_unique_id( # Failure to migrate config entry to a unique id responses.insert(0, mock_response_error(HTTPStatus.SERVICE_UNAVAILABLE)) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED rainsensor = hass.states.get("binary_sensor.rain_bird_controller_rainsensor") diff --git a/tests/components/rainbird/test_calendar.py b/tests/components/rainbird/test_calendar.py index 44baf09fd55..673d32998d5 100644 --- a/tests/components/rainbird/test_calendar.py +++ b/tests/components/rainbird/test_calendar.py @@ -87,7 +87,7 @@ async def setup_config_entry( hass: HomeAssistant, config_entry: MockConfigEntry ) -> list[Platform]: """Fixture to setup the config entry.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED @@ -191,7 +191,7 @@ async def test_event_state( """Test calendar upcoming event state.""" freezer.move_to(freeze_time) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED state = hass.states.get(TEST_ENTITY) @@ -298,7 +298,7 @@ async def test_no_unique_id( # Failure to migrate config entry to a unique id responses.insert(0, mock_response_error(HTTPStatus.SERVICE_UNAVAILABLE)) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED state = hass.states.get(TEST_ENTITY) diff --git a/tests/components/rainbird/test_config_flow.py b/tests/components/rainbird/test_config_flow.py index 7a4dc2a55d4..09db734f1ad 100644 --- a/tests/components/rainbird/test_config_flow.py +++ b/tests/components/rainbird/test_config_flow.py @@ -158,7 +158,7 @@ async def test_multiple_config_entries( expected_config_entry: dict[str, Any] | None, ) -> None: """Test setting up multiple config entries that refer to different devices.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED responses.clear() @@ -233,7 +233,7 @@ async def test_duplicate_config_entries( expected_config_entry_data: dict[str, Any], ) -> None: """Test that a device can not be registered twice.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED responses.clear() diff --git a/tests/components/rainbird/test_number.py b/tests/components/rainbird/test_number.py index 79b8fd5ec37..b0c1856819e 100644 --- a/tests/components/rainbird/test_number.py +++ b/tests/components/rainbird/test_number.py @@ -37,7 +37,7 @@ async def setup_config_entry( hass: HomeAssistant, config_entry: MockConfigEntry ) -> list[Platform]: """Fixture to setup the config entry.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED @@ -155,7 +155,7 @@ async def test_no_unique_id( # Failure to migrate config entry to a unique id responses.insert(0, mock_response_error(HTTPStatus.SERVICE_UNAVAILABLE)) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED raindelay = hass.states.get("number.rain_bird_controller_rain_delay") diff --git a/tests/components/rainbird/test_sensor.py b/tests/components/rainbird/test_sensor.py index 2a0195f8d97..ebe852ccf46 100644 --- a/tests/components/rainbird/test_sensor.py +++ b/tests/components/rainbird/test_sensor.py @@ -31,7 +31,7 @@ async def setup_config_entry( hass: HomeAssistant, config_entry: MockConfigEntry ) -> list[Platform]: """Fixture to setup the config entry.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED @@ -85,7 +85,7 @@ async def test_sensor_no_unique_id( # Failure to migrate config entry to a unique id responses.insert(0, mock_response_error(HTTPStatus.SERVICE_UNAVAILABLE)) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED raindelay = hass.states.get("sensor.rain_bird_controller_raindelay") diff --git a/tests/components/rainbird/test_switch.py b/tests/components/rainbird/test_switch.py index f9c03f63dd3..0f9a139a69d 100644 --- a/tests/components/rainbird/test_switch.py +++ b/tests/components/rainbird/test_switch.py @@ -43,7 +43,7 @@ async def setup_config_entry( hass: HomeAssistant, config_entry: MockConfigEntry ) -> list[Platform]: """Fixture to setup the config entry.""" - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED @@ -293,7 +293,7 @@ async def test_no_unique_id( # Failure to migrate config entry to a unique id responses.insert(0, mock_response_error(HTTPStatus.SERVICE_UNAVAILABLE)) - await config_entry.async_setup(hass) + await hass.config_entries.async_setup(config_entry.entry_id) assert config_entry.state == ConfigEntryState.LOADED zone = hass.states.get("switch.rain_bird_sprinkler_3")