Use service_calls fixture in lg_netcast tests (#120932)

This commit is contained in:
epenet 2024-07-01 17:37:29 +02:00 committed by GitHub
parent c4903dd982
commit 788d1999ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 29 deletions

View File

@ -1,13 +0,0 @@
"""Common fixtures and objects for the LG Netcast integration tests."""
import pytest
from homeassistant.core import HomeAssistant, ServiceCall
from tests.common import async_mock_service
@pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")

View File

@ -43,7 +43,9 @@ async def test_get_triggers(
async def test_if_fires_on_turn_on_request( async def test_if_fires_on_turn_on_request(
hass: HomeAssistant, calls: list[ServiceCall], device_registry: dr.DeviceRegistry hass: HomeAssistant,
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test for turn_on triggers firing.""" """Test for turn_on triggers firing."""
await setup_lgnetcast(hass) await setup_lgnetcast(hass)
@ -96,11 +98,11 @@ async def test_if_fires_on_turn_on_request(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 2 assert len(service_calls) == 3
assert calls[0].data["some"] == device.id assert service_calls[1].data["some"] == device.id
assert calls[0].data["id"] == 0 assert service_calls[1].data["id"] == 0
assert calls[1].data["some"] == ENTITY_ID assert service_calls[2].data["some"] == ENTITY_ID
assert calls[1].data["id"] == 0 assert service_calls[2].data["id"] == 0
async def test_failure_scenarios( async def test_failure_scenarios(

View File

@ -18,7 +18,9 @@ from tests.common import MockEntity, MockEntityPlatform
async def test_lg_netcast_turn_on_trigger_device_id( async def test_lg_netcast_turn_on_trigger_device_id(
hass: HomeAssistant, calls: list[ServiceCall], device_registry: dr.DeviceRegistry hass: HomeAssistant,
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test for turn_on trigger by device_id firing.""" """Test for turn_on trigger by device_id firing."""
await setup_lgnetcast(hass) await setup_lgnetcast(hass)
@ -56,14 +58,14 @@ async def test_lg_netcast_turn_on_trigger_device_id(
) )
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"] == device.id assert service_calls[1].data["some"] == device.id
assert calls[0].data["id"] == 0 assert service_calls[1].data["id"] == 0
with patch("homeassistant.config.load_yaml_dict", return_value={}): with patch("homeassistant.config.load_yaml_dict", return_value={}):
await hass.services.async_call(automation.DOMAIN, SERVICE_RELOAD, blocking=True) await hass.services.async_call(automation.DOMAIN, SERVICE_RELOAD, blocking=True)
calls.clear() service_calls.clear()
with pytest.raises(HomeAssistantError): with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
@ -74,11 +76,11 @@ async def test_lg_netcast_turn_on_trigger_device_id(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 0 assert len(service_calls) == 1
async def test_lg_netcast_turn_on_trigger_entity_id( async def test_lg_netcast_turn_on_trigger_entity_id(
hass: HomeAssistant, calls: list[ServiceCall] hass: HomeAssistant, service_calls: list[ServiceCall]
) -> None: ) -> None:
"""Test for turn_on triggers by entity firing.""" """Test for turn_on triggers by entity firing."""
await setup_lgnetcast(hass) await setup_lgnetcast(hass)
@ -113,9 +115,9 @@ async def test_lg_netcast_turn_on_trigger_entity_id(
) )
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"] == ENTITY_ID assert service_calls[1].data["some"] == ENTITY_ID
assert calls[0].data["id"] == 0 assert service_calls[1].data["id"] == 0
async def test_wrong_trigger_platform_type( async def test_wrong_trigger_platform_type(