Use service_calls fixture in webostv tests (#120999)

This commit is contained in:
epenet 2024-07-04 22:07:38 +02:00 committed by GitHub
parent 84a8259103
commit 83fac6192d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 25 deletions

View File

@ -6,12 +6,9 @@ from unittest.mock import AsyncMock, Mock, patch
import pytest
from homeassistant.components.webostv.const import LIVE_TV_APP_ID
from homeassistant.core import HomeAssistant, ServiceCall
from .const import CHANNEL_1, CHANNEL_2, CLIENT_KEY, FAKE_UUID, MOCK_APPS, MOCK_INPUTS
from tests.common import async_mock_service
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
@ -22,12 +19,6 @@ def mock_setup_entry() -> Generator[AsyncMock]:
yield mock_setup_entry
@pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")
@pytest.fixture(name="client")
def client_fixture():
"""Patch of client library for tests."""

View File

@ -44,7 +44,7 @@ async def test_get_triggers(
async def test_if_fires_on_turn_on_request(
hass: HomeAssistant,
calls: list[ServiceCall],
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
client,
) -> None:
@ -97,11 +97,11 @@ async def test_if_fires_on_turn_on_request(
blocking=True,
)
assert len(calls) == 2
assert calls[0].data["some"] == device.id
assert calls[0].data["id"] == 0
assert calls[1].data["some"] == ENTITY_ID
assert calls[1].data["id"] == 0
assert len(service_calls) == 3
assert service_calls[1].data["some"] == device.id
assert service_calls[1].data["id"] == 0
assert service_calls[2].data["some"] == ENTITY_ID
assert service_calls[2].data["id"] == 0
async def test_failure_scenarios(

View File

@ -20,7 +20,7 @@ from tests.common import MockEntity, MockEntityPlatform
async def test_webostv_turn_on_trigger_device_id(
hass: HomeAssistant,
calls: list[ServiceCall],
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
client,
) -> None:
@ -58,14 +58,14 @@ async def test_webostv_turn_on_trigger_device_id(
blocking=True,
)
assert len(calls) == 1
assert calls[0].data["some"] == device.id
assert calls[0].data["id"] == 0
assert len(service_calls) == 2
assert service_calls[1].data["some"] == device.id
assert service_calls[1].data["id"] == 0
with patch("homeassistant.config.load_yaml_dict", return_value={}):
await hass.services.async_call(automation.DOMAIN, SERVICE_RELOAD, blocking=True)
calls.clear()
service_calls.clear()
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
@ -75,11 +75,11 @@ async def test_webostv_turn_on_trigger_device_id(
blocking=True,
)
assert len(calls) == 0
assert len(service_calls) == 1
async def test_webostv_turn_on_trigger_entity_id(
hass: HomeAssistant, calls: list[ServiceCall], client
hass: HomeAssistant, service_calls: list[ServiceCall], client
) -> None:
"""Test for turn_on triggers by entity_id firing."""
await setup_webostv(hass)
@ -113,9 +113,9 @@ async def test_webostv_turn_on_trigger_entity_id(
blocking=True,
)
assert len(calls) == 1
assert calls[0].data["some"] == ENTITY_ID
assert calls[0].data["id"] == 0
assert len(service_calls) == 2
assert service_calls[1].data["some"] == ENTITY_ID
assert service_calls[1].data["id"] == 0
async def test_wrong_trigger_platform_type(