Clean up unnecessary registry mocks from Core tests (#87726)

This commit is contained in:
Franck Nijhof 2023-02-08 20:28:44 +01:00 committed by GitHub
parent 899adef590
commit 51a9f65a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 882 additions and 1455 deletions

View file

@ -12,7 +12,7 @@ from homeassistant.components.light import (
LightEntityFeature,
)
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component
@ -23,39 +23,25 @@ from tests.common import (
async_get_device_automation_capabilities,
async_get_device_automations,
async_mock_service,
mock_device_registry,
mock_registry,
)
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture
def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")
async def test_get_actions(hass, device_reg, entity_reg):
async def test_get_actions(hass, device_registry, entity_registry):
"""Test we get the expected actions from a light."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(
entity_registry.async_get_or_create(
DOMAIN,
"test",
"5678",
@ -98,19 +84,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
)
async def test_get_actions_hidden_auxiliary(
hass,
device_reg,
entity_reg,
device_registry,
entity_registry,
hidden_by,
entity_category,
):
"""Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(
entity_registry.async_get_or_create(
DOMAIN,
"test",
"5678",
@ -137,16 +123,16 @@ async def test_get_actions_hidden_auxiliary(
assert_lists_same(actions, expected_actions)
async def test_get_action_capabilities(hass, device_reg, entity_reg):
async def test_get_action_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a light action."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
# Test with entity without optional capabilities
entity_id = entity_reg.async_get_or_create(
entity_id = entity_registry.async_get_or_create(
DOMAIN,
"test",
"5678",
@ -165,7 +151,7 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
assert capabilities == {"extra_fields": []}
# Test without entity
entity_reg.async_remove(entity_id)
entity_registry.async_remove(entity_id)
for action in actions:
capabilities = await async_get_device_automation_capabilities(
hass, DeviceAutomationType.ACTION, action
@ -266,8 +252,8 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
)
async def test_get_action_capabilities_features(
hass,
device_reg,
entity_reg,
device_registry,
entity_registry,
set_state,
expected_actions,
supported_features_reg,
@ -279,11 +265,11 @@ async def test_get_action_capabilities_features(
"""Test we get the expected capabilities from a light action."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_id = entity_reg.async_get_or_create(
entity_id = entity_registry.async_get_or_create(
DOMAIN,
"test",
"5678",