mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Improve dlna_dmr tests (#102905)
This commit is contained in:
parent
6f515c06a2
commit
524e20536d
@ -74,8 +74,8 @@ def domain_data_mock(hass: HomeAssistant) -> Iterable[Mock]:
|
|||||||
seal(upnp_device)
|
seal(upnp_device)
|
||||||
domain_data.upnp_factory.async_create_device.return_value = upnp_device
|
domain_data.upnp_factory.async_create_device.return_value = upnp_device
|
||||||
|
|
||||||
with patch.dict(hass.data, {DLNA_DOMAIN: domain_data}):
|
hass.data[DLNA_DOMAIN] = domain_data
|
||||||
yield domain_data
|
return domain_data
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -129,6 +129,7 @@ def dmr_device_mock(domain_data_mock: Mock) -> Iterable[Mock]:
|
|||||||
device.manufacturer = "device_manufacturer"
|
device.manufacturer = "device_manufacturer"
|
||||||
device.model_name = "device_model_name"
|
device.model_name = "device_model_name"
|
||||||
device.name = "device_name"
|
device.name = "device_name"
|
||||||
|
device.preset_names = ["preset1", "preset2"]
|
||||||
|
|
||||||
yield device
|
yield device
|
||||||
|
|
||||||
|
@ -97,6 +97,15 @@ def mock_get_mac_address() -> Iterable[Mock]:
|
|||||||
yield gma_mock
|
yield gma_mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mock_setup_entry() -> Iterable[Mock]:
|
||||||
|
"""Mock async_setup_entry."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.dlna_dmr.async_setup_entry", return_value=True
|
||||||
|
) as setup_entry_mock:
|
||||||
|
yield setup_entry_mock
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_undiscovered_manual(hass: HomeAssistant) -> None:
|
async def test_user_flow_undiscovered_manual(hass: HomeAssistant) -> None:
|
||||||
"""Test user-init'd flow, no discovered devices, user entering a valid URL."""
|
"""Test user-init'd flow, no discovered devices, user entering a valid URL."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -120,9 +129,6 @@ async def test_user_flow_undiscovered_manual(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_discovered_manual(
|
async def test_user_flow_discovered_manual(
|
||||||
hass: HomeAssistant, ssdp_scanner_mock: Mock
|
hass: HomeAssistant, ssdp_scanner_mock: Mock
|
||||||
@ -163,9 +169,6 @@ async def test_user_flow_discovered_manual(
|
|||||||
}
|
}
|
||||||
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_selected(hass: HomeAssistant, ssdp_scanner_mock: Mock) -> None:
|
async def test_user_flow_selected(hass: HomeAssistant, ssdp_scanner_mock: Mock) -> None:
|
||||||
"""Test user-init'd flow, user selects discovered device."""
|
"""Test user-init'd flow, user selects discovered device."""
|
||||||
@ -196,8 +199,6 @@ async def test_user_flow_selected(hass: HomeAssistant, ssdp_scanner_mock: Mock)
|
|||||||
}
|
}
|
||||||
assert result["options"] == {}
|
assert result["options"] == {}
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_uncontactable(
|
async def test_user_flow_uncontactable(
|
||||||
hass: HomeAssistant, domain_data_mock: Mock
|
hass: HomeAssistant, domain_data_mock: Mock
|
||||||
@ -260,9 +261,6 @@ async def test_user_flow_embedded_st(
|
|||||||
}
|
}
|
||||||
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_wrong_st(hass: HomeAssistant, domain_data_mock: Mock) -> None:
|
async def test_user_flow_wrong_st(hass: HomeAssistant, domain_data_mock: Mock) -> None:
|
||||||
"""Test user-init'd config flow with user entering a URL for the wrong device."""
|
"""Test user-init'd config flow with user entering a URL for the wrong device."""
|
||||||
@ -717,9 +715,6 @@ async def test_unignore_flow(hass: HomeAssistant, ssdp_scanner_mock: Mock) -> No
|
|||||||
}
|
}
|
||||||
assert result["options"] == {}
|
assert result["options"] == {}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_unignore_flow_offline(
|
async def test_unignore_flow_offline(
|
||||||
hass: HomeAssistant, ssdp_scanner_mock: Mock
|
hass: HomeAssistant, ssdp_scanner_mock: Mock
|
||||||
|
@ -26,7 +26,6 @@ from homeassistant.components.dlna_dmr.const import (
|
|||||||
CONF_CALLBACK_URL_OVERRIDE,
|
CONF_CALLBACK_URL_OVERRIDE,
|
||||||
CONF_LISTEN_PORT,
|
CONF_LISTEN_PORT,
|
||||||
CONF_POLL_AVAILABILITY,
|
CONF_POLL_AVAILABILITY,
|
||||||
DOMAIN as DLNA_DOMAIN,
|
|
||||||
)
|
)
|
||||||
from homeassistant.components.dlna_dmr.data import EventListenAddr
|
from homeassistant.components.dlna_dmr.data import EventListenAddr
|
||||||
from homeassistant.components.dlna_dmr.media_player import DlnaDmrEntity
|
from homeassistant.components.dlna_dmr.media_player import DlnaDmrEntity
|
||||||
@ -81,7 +80,7 @@ pytestmark = pytest.mark.usefixtures("domain_data_mock")
|
|||||||
async def setup_mock_component(hass: HomeAssistant, mock_entry: MockConfigEntry) -> str:
|
async def setup_mock_component(hass: HomeAssistant, mock_entry: MockConfigEntry) -> str:
|
||||||
"""Set up a mock DlnaDmrEntity with the given configuration."""
|
"""Set up a mock DlnaDmrEntity with the given configuration."""
|
||||||
mock_entry.add_to_hass(hass)
|
mock_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(hass, DLNA_DOMAIN, {}) is True
|
assert await hass.config_entries.async_setup(mock_entry.entry_id) is True
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entries = async_entries_for_config_entry(async_get_er(hass), mock_entry.entry_id)
|
entries = async_entries_for_config_entry(async_get_er(hass), mock_entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user