Cleanup test config entry setup to use best practices (#110070)

* Cleanup test config entry setup to use best practices

* Add missed files
pull/110076/head
Allen Porter 2024-02-08 19:52:40 -08:00 committed by GitHub
parent 2d8d6ce642
commit 261f9c5d62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 29 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -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)

View File

@ -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()

View File

@ -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")

View File

@ -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")

View File

@ -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")