Unifiprotect replace direct mocks with MockConfigEntry for test_async_ufp_instance_for_config_entry_ids (#131736)
Co-authored-by: J. Nick Koston <nick@koston.org>pull/131702/head^2
parent
fda178da23
commit
1f1fdf80db
|
@ -297,15 +297,15 @@ async def test_device_remove_devices_nvr(
|
||||||
[
|
[
|
||||||
pytest.param(
|
pytest.param(
|
||||||
[
|
[
|
||||||
Mock(
|
MockConfigEntry(
|
||||||
spec=ConfigEntry,
|
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
runtime_data=Mock(api="mock_api_instance_1"),
|
entry_id="1",
|
||||||
|
data={},
|
||||||
),
|
),
|
||||||
Mock(
|
MockConfigEntry(
|
||||||
spec=ConfigEntry,
|
|
||||||
domain="other_domain",
|
domain="other_domain",
|
||||||
runtime_data=Mock(api="mock_api_instance_2"),
|
entry_id="2",
|
||||||
|
data={},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
"mock_api_instance_1",
|
"mock_api_instance_1",
|
||||||
|
@ -313,15 +313,15 @@ async def test_device_remove_devices_nvr(
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
[
|
[
|
||||||
Mock(
|
MockConfigEntry(
|
||||||
spec=ConfigEntry,
|
|
||||||
domain="other_domain",
|
domain="other_domain",
|
||||||
runtime_data=Mock(api="mock_api_instance_1"),
|
entry_id="1",
|
||||||
|
data={},
|
||||||
),
|
),
|
||||||
Mock(
|
MockConfigEntry(
|
||||||
spec=ConfigEntry,
|
|
||||||
domain="other_domain",
|
domain="other_domain",
|
||||||
runtime_data=Mock(api="mock_api_instance_2"),
|
entry_id="2",
|
||||||
|
data={},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
|
@ -330,22 +330,17 @@ async def test_device_remove_devices_nvr(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_async_ufp_instance_for_config_entry_ids(
|
async def test_async_ufp_instance_for_config_entry_ids(
|
||||||
mock_entries, expected_result
|
hass: HomeAssistant,
|
||||||
|
mock_entries: list[MockConfigEntry],
|
||||||
|
expected_result: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test async_ufp_instance_for_config_entry_ids with various entry configurations."""
|
"""Test async_ufp_instance_for_config_entry_ids with various entry configurations."""
|
||||||
|
|
||||||
hass = Mock(spec=HomeAssistant)
|
for index, entry in enumerate(mock_entries):
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
entry.runtime_data = Mock(api=f"mock_api_instance_{index + 1}")
|
||||||
|
|
||||||
mock_entry_mapping = {
|
entry_ids = {entry.entry_id for entry in mock_entries}
|
||||||
str(index): entry for index, entry in enumerate(mock_entries, start=1)
|
|
||||||
}
|
|
||||||
|
|
||||||
def mock_async_get_entry(entry_id):
|
|
||||||
return mock_entry_mapping.get(entry_id)
|
|
||||||
|
|
||||||
hass.config_entries.async_get_entry = Mock(side_effect=mock_async_get_entry)
|
|
||||||
|
|
||||||
entry_ids = set(mock_entry_mapping.keys())
|
|
||||||
|
|
||||||
result = async_ufp_instance_for_config_entry_ids(hass, entry_ids)
|
result = async_ufp_instance_for_config_entry_ids(hass, entry_ids)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue