Avoid directly changing config entry state in tests (part 2) (#110115)

followup to #110048 for more places
pull/110191/head
J. Nick Koston 2024-02-10 00:20:15 -06:00 committed by GitHub
parent 567a179084
commit f6d4617c7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 22 additions and 22 deletions

View File

@ -934,7 +934,7 @@ class MockConfigEntry(config_entries.ConfigEntry):
kwargs["state"] = state
super().__init__(**kwargs)
if reason is not None:
self.reason = reason
object.__setattr__(self, "reason", reason)
def add_to_hass(self, hass: HomeAssistant) -> None:
"""Test helper to add entry to hass."""

View File

@ -47,7 +47,7 @@ async def test_notify_leaving_zone(
) -> None:
"""Test notifying leaving a zone blueprint."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device = device_registry.async_get_or_create(

View File

@ -1601,7 +1601,7 @@ async def test_extraction_functions(
) -> None:
"""Test extraction functions."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
condition_device = device_registry.async_get_or_create(

View File

@ -976,7 +976,7 @@ async def test_automation_with_dynamically_validated_action(
module.async_validate_action_config = AsyncMock()
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1078,7 +1078,7 @@ async def test_automation_with_dynamically_validated_condition(
module.async_validate_condition_config = AsyncMock()
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1192,7 +1192,7 @@ async def test_automation_with_dynamically_validated_trigger(
module.async_validate_trigger_config = AsyncMock(wraps=lambda hass, config: config)
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1295,7 +1295,7 @@ async def test_automation_with_bad_action(
) -> None:
"""Test automation with bad device action."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1329,7 +1329,7 @@ async def test_automation_with_bad_condition_action(
) -> None:
"""Test automation with bad device action."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1362,7 +1362,7 @@ async def test_automation_with_bad_condition(
) -> None:
"""Test automation with bad device condition."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1527,7 +1527,7 @@ async def test_automation_with_bad_sub_condition(
) -> None:
"""Test automation with bad device condition under and/or conditions."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
@ -1565,7 +1565,7 @@ async def test_automation_with_bad_trigger(
) -> None:
"""Test automation with bad device trigger."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,

View File

@ -497,7 +497,7 @@ async def test_dhcp_discovery_updates_unique_id_when_entry_is_failed(
unique_id="1.2.3.4",
)
entry.add_to_hass(hass)
entry.state = config_entries.ConfigEntryState.SETUP_ERROR
entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_ERROR)
mock_powerwall = await _mock_powerwall_site_name(hass, "Some site")
with patch(

View File

@ -47,7 +47,7 @@ async def test_confirmable_notification(
) -> None:
"""Test confirmable notification blueprint."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
frodo = device_registry.async_get_or_create(

View File

@ -718,7 +718,7 @@ async def test_extraction_functions(
) -> None:
"""Test extraction functions."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_in_both = device_registry.async_get_or_create(

View File

@ -2435,7 +2435,7 @@ async def test_execute_script_with_dynamically_validated_action(
)
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,

View File

@ -1587,7 +1587,7 @@ async def test_options_flow_defaults(
mock_async_unload.assert_called_once_with(entry.entry_id)
# Unload it ourselves
entry.state = config_entries.ConfigEntryState.NOT_LOADED
entry.mock_state(hass, config_entries.ConfigEntryState.NOT_LOADED)
# Reconfigure ZHA
assert result1["step_id"] == "prompt_migrate_or_reconfigure"
@ -1770,7 +1770,7 @@ async def test_options_flow_restarts_running_zha_if_cancelled(
flow["flow_id"], user_input={}
)
entry.state = config_entries.ConfigEntryState.NOT_LOADED
entry.mock_state(hass, config_entries.ConfigEntryState.NOT_LOADED)
assert result1["step_id"] == "prompt_migrate_or_reconfigure"
result2 = await hass.config_entries.options.async_configure(
@ -1825,7 +1825,7 @@ async def test_options_flow_migration_reset_old_adapter(
flow["flow_id"], user_input={}
)
entry.state = config_entries.ConfigEntryState.NOT_LOADED
entry.mock_state(hass, config_entries.ConfigEntryState.NOT_LOADED)
assert result1["step_id"] == "prompt_migrate_or_reconfigure"
result2 = await hass.config_entries.options.async_configure(

View File

@ -224,7 +224,7 @@ async def test_migrate_matching_port_config_entry_not_loaded(
title="Test",
)
config_entry.add_to_hass(hass)
config_entry.state = config_entries.ConfigEntryState.SETUP_IN_PROGRESS
config_entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS)
migration_data = {
"new_discovery_info": {
@ -284,7 +284,7 @@ async def test_migrate_matching_port_retry(
title="Test",
)
config_entry.add_to_hass(hass)
config_entry.state = config_entries.ConfigEntryState.SETUP_IN_PROGRESS
config_entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS)
migration_data = {
"new_discovery_info": {
@ -389,7 +389,7 @@ async def test_migrate_initiate_failure(
title="Test",
)
config_entry.add_to_hass(hass)
config_entry.state = config_entries.ConfigEntryState.SETUP_IN_PROGRESS
config_entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS)
migration_data = {
"new_discovery_info": {

View File

@ -4633,7 +4633,7 @@ async def test_validate_action_config(
"""Validate action config."""
config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED)
config_entry.add_to_hass(hass)
mock_device = device_registry.async_get_or_create(