Use service_calls fixture in kodi tests (#120929)

This commit is contained in:
epenet 2024-07-01 17:55:01 +02:00 committed by GitHub
parent c6cfe073ea
commit b3a50893cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,11 +12,7 @@ from homeassistant.setup import async_setup_component
from . import init_integration from . import init_integration
from tests.common import ( from tests.common import MockConfigEntry, async_get_device_automations
MockConfigEntry,
async_get_device_automations,
async_mock_service,
)
@pytest.fixture(autouse=True, name="stub_blueprint_populate") @pytest.fixture(autouse=True, name="stub_blueprint_populate")
@ -24,12 +20,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
"""Stub copying the blueprints to the config folder.""" """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")
@pytest.fixture @pytest.fixture
async def kodi_media_player(hass): async def kodi_media_player(hass):
"""Get a kodi media player.""" """Get a kodi media player."""
@ -77,7 +67,7 @@ async def test_get_triggers(
async def test_if_fires_on_state_change( async def test_if_fires_on_state_change(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
calls: list[ServiceCall], service_calls: list[ServiceCall],
kodi_media_player, kodi_media_player,
) -> None: ) -> None:
"""Test for turn_on and turn_off triggers firing.""" """Test for turn_on and turn_off triggers firing."""
@ -135,8 +125,8 @@ async def test_if_fires_on_state_change(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 1 assert len(service_calls) == 2
assert calls[0].data["some"] == f"turn_on - {kodi_media_player} - 0" assert service_calls[1].data["some"] == f"turn_on - {kodi_media_player} - 0"
await hass.services.async_call( await hass.services.async_call(
MP_DOMAIN, MP_DOMAIN,
@ -146,14 +136,14 @@ async def test_if_fires_on_state_change(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 2 assert len(service_calls) == 4
assert calls[1].data["some"] == f"turn_off - {kodi_media_player} - 0" assert service_calls[3].data["some"] == f"turn_off - {kodi_media_player} - 0"
async def test_if_fires_on_state_change_legacy( async def test_if_fires_on_state_change_legacy(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
calls: list[ServiceCall], service_calls: list[ServiceCall],
kodi_media_player, kodi_media_player,
) -> None: ) -> None:
"""Test for turn_on and turn_off triggers firing.""" """Test for turn_on and turn_off triggers firing."""
@ -194,5 +184,5 @@ async def test_if_fires_on_state_change_legacy(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 1 assert len(service_calls) == 2
assert calls[0].data["some"] == f"turn_on - {kodi_media_player} - 0" assert service_calls[1].data["some"] == f"turn_on - {kodi_media_player} - 0"