mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use service_calls fixture in microsoft tests (#120983)
This commit is contained in:
parent
71b7ee40e5
commit
b13e78f3a3
@ -8,18 +8,13 @@ from pycsspeechtts import pycsspeechtts
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import tts
|
from homeassistant.components import tts
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import ATTR_MEDIA_CONTENT_ID
|
||||||
ATTR_MEDIA_CONTENT_ID,
|
|
||||||
DOMAIN as DOMAIN_MP,
|
|
||||||
SERVICE_PLAY_MEDIA,
|
|
||||||
)
|
|
||||||
from homeassistant.components.microsoft.tts import SUPPORTED_LANGUAGES
|
from homeassistant.components.microsoft.tts import SUPPORTED_LANGUAGES
|
||||||
from homeassistant.config import async_process_ha_core_config
|
from homeassistant.config import async_process_ha_core_config
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.exceptions import ServiceNotFound
|
from homeassistant.exceptions import ServiceNotFound
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
|
||||||
from tests.components.tts.common import retrieve_media
|
from tests.components.tts.common import retrieve_media
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
@ -30,12 +25,6 @@ def mock_tts_cache_dir_autouse(mock_tts_cache_dir: Path) -> Path:
|
|||||||
return mock_tts_cache_dir
|
return mock_tts_cache_dir
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
|
||||||
"""Mock media player calls."""
|
|
||||||
return async_mock_service(hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_internal_url(hass: HomeAssistant):
|
async def setup_internal_url(hass: HomeAssistant):
|
||||||
"""Set up internal url."""
|
"""Set up internal url."""
|
||||||
@ -58,7 +47,7 @@ async def test_service_say(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
mock_tts,
|
mock_tts,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service call say."""
|
"""Test service call say."""
|
||||||
|
|
||||||
@ -77,9 +66,11 @@ async def test_service_say(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert (
|
assert (
|
||||||
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
|
await retrieve_media(
|
||||||
|
hass, hass_client, service_calls[1].data[ATTR_MEDIA_CONTENT_ID]
|
||||||
|
)
|
||||||
== HTTPStatus.OK
|
== HTTPStatus.OK
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,7 +93,7 @@ async def test_service_say_en_gb_config(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
mock_tts,
|
mock_tts,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service call say with en-gb code in the config."""
|
"""Test service call say with en-gb code in the config."""
|
||||||
|
|
||||||
@ -130,9 +121,11 @@ async def test_service_say_en_gb_config(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert (
|
assert (
|
||||||
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
|
await retrieve_media(
|
||||||
|
hass, hass_client, service_calls[1].data[ATTR_MEDIA_CONTENT_ID]
|
||||||
|
)
|
||||||
== HTTPStatus.OK
|
== HTTPStatus.OK
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -154,7 +147,7 @@ async def test_service_say_en_gb_service(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
mock_tts,
|
mock_tts,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service call say with en-gb code in the service."""
|
"""Test service call say with en-gb code in the service."""
|
||||||
|
|
||||||
@ -177,9 +170,11 @@ async def test_service_say_en_gb_service(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert (
|
assert (
|
||||||
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
|
await retrieve_media(
|
||||||
|
hass, hass_client, service_calls[1].data[ATTR_MEDIA_CONTENT_ID]
|
||||||
|
)
|
||||||
== HTTPStatus.OK
|
== HTTPStatus.OK
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -201,7 +196,7 @@ async def test_service_say_fa_ir_config(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
mock_tts,
|
mock_tts,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service call say with fa-ir code in the config."""
|
"""Test service call say with fa-ir code in the config."""
|
||||||
|
|
||||||
@ -229,9 +224,11 @@ async def test_service_say_fa_ir_config(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert (
|
assert (
|
||||||
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
|
await retrieve_media(
|
||||||
|
hass, hass_client, service_calls[1].data[ATTR_MEDIA_CONTENT_ID]
|
||||||
|
)
|
||||||
== HTTPStatus.OK
|
== HTTPStatus.OK
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -253,7 +250,7 @@ async def test_service_say_fa_ir_service(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
mock_tts,
|
mock_tts,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service call say with fa-ir code in the service."""
|
"""Test service call say with fa-ir code in the service."""
|
||||||
|
|
||||||
@ -280,9 +277,11 @@ async def test_service_say_fa_ir_service(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert (
|
assert (
|
||||||
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
|
await retrieve_media(
|
||||||
|
hass, hass_client, service_calls[1].data[ATTR_MEDIA_CONTENT_ID]
|
||||||
|
)
|
||||||
== HTTPStatus.OK
|
== HTTPStatus.OK
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -317,9 +316,7 @@ def test_supported_languages() -> None:
|
|||||||
assert len(SUPPORTED_LANGUAGES) > 100
|
assert len(SUPPORTED_LANGUAGES) > 100
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_language(
|
async def test_invalid_language(hass: HomeAssistant, mock_tts) -> None:
|
||||||
hass: HomeAssistant, mock_tts, calls: list[ServiceCall]
|
|
||||||
) -> None:
|
|
||||||
"""Test setup component with invalid language."""
|
"""Test setup component with invalid language."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -339,7 +336,6 @@ async def test_invalid_language(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 0
|
|
||||||
assert len(mock_tts.mock_calls) == 0
|
assert len(mock_tts.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
@ -347,7 +343,7 @@ async def test_service_say_error(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
mock_tts,
|
mock_tts,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service call say with http error."""
|
"""Test service call say with http error."""
|
||||||
mock_tts.return_value.speak.side_effect = pycsspeechtts.requests.HTTPError
|
mock_tts.return_value.speak.side_effect = pycsspeechtts.requests.HTTPError
|
||||||
@ -366,9 +362,11 @@ async def test_service_say_error(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 2
|
||||||
assert (
|
assert (
|
||||||
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
|
await retrieve_media(
|
||||||
|
hass, hass_client, service_calls[1].data[ATTR_MEDIA_CONTENT_ID]
|
||||||
|
)
|
||||||
== HTTPStatus.NOT_FOUND
|
== HTTPStatus.NOT_FOUND
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user