Use common fixtures in philips_js tests (#120988)

pull/121012/head
epenet 2024-07-02 12:31:10 +02:00 committed by GitHub
parent e544550380
commit 6fd1f0a34f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 27 deletions

View File

@ -7,10 +7,12 @@ from haphilipsjs import PhilipsTV
import pytest
from homeassistant.components.philips_js.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from . import MOCK_CONFIG, MOCK_ENTITY_ID, MOCK_NAME, MOCK_SERIAL_NO, MOCK_SYSTEM
from tests.common import MockConfigEntry, mock_device_registry
from tests.common import MockConfigEntry
@pytest.fixture
@ -27,11 +29,6 @@ def mock_setup_entry() -> Generator[AsyncMock]:
yield mock_setup_entry
@pytest.fixture(autouse=True)
async def setup_notification(hass):
"""Configure notification system."""
@pytest.fixture(autouse=True)
def mock_tv():
"""Disable component actual use."""
@ -62,7 +59,7 @@ def mock_tv():
@pytest.fixture
async def mock_config_entry(hass):
async def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Get standard player."""
config_entry = MockConfigEntry(
domain=DOMAIN, data=MOCK_CONFIG, title=MOCK_NAME, unique_id=MOCK_SERIAL_NO
@ -72,13 +69,7 @@ async def mock_config_entry(hass):
@pytest.fixture
def mock_device_reg(hass):
"""Get standard device."""
return mock_device_registry(hass)
@pytest.fixture
async def mock_entity(hass, mock_device_reg, mock_config_entry):
async def mock_entity(hass: HomeAssistant, mock_config_entry: MockConfigEntry) -> str:
"""Get standard player."""
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
@ -86,9 +77,13 @@ async def mock_entity(hass, mock_device_reg, mock_config_entry):
@pytest.fixture
def mock_device(hass, mock_device_reg, mock_entity, mock_config_entry):
def mock_device(
device_registry: dr.DeviceRegistry,
mock_entity: str,
mock_config_entry: MockConfigEntry,
) -> dr.DeviceEntry:
"""Get standard device."""
return mock_device_reg.async_get_or_create(
return device_registry.async_get_or_create(
config_entry_id=mock_config_entry.entry_id,
identifiers={(DOMAIN, MOCK_SERIAL_NO)},
)

View File

@ -9,7 +9,7 @@ from homeassistant.components.philips_js.const import DOMAIN
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.setup import async_setup_component
from tests.common import async_get_device_automations, async_mock_service
from tests.common import async_get_device_automations
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
@ -17,12 +17,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
"""Stub copying the blueprints to the config folder."""
@pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass: HomeAssistant, mock_device) -> None:
"""Test we get the expected triggers."""
expected_triggers = [
@ -42,7 +36,11 @@ async def test_get_triggers(hass: HomeAssistant, mock_device) -> None:
async def test_if_fires_on_turn_on_request(
hass: HomeAssistant, calls: list[ServiceCall], mock_tv, mock_entity, mock_device
hass: HomeAssistant,
service_calls: list[ServiceCall],
mock_tv,
mock_entity,
mock_device,
) -> None:
"""Test for turn_on and turn_off triggers firing."""
@ -80,6 +78,10 @@ async def test_if_fires_on_turn_on_request(
)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == mock_device.id
assert calls[0].data["id"] == 0
assert len(service_calls) == 2
assert service_calls[0].domain == "media_player"
assert service_calls[0].service == "turn_on"
assert service_calls[1].domain == "test"
assert service_calls[1].service == "automation"
assert service_calls[1].data["some"] == mock_device.id
assert service_calls[1].data["id"] == 0