diff --git a/tests/components/microsoft/test_tts.py b/tests/components/microsoft/test_tts.py index 082def901c5..dca760230ac 100644 --- a/tests/components/microsoft/test_tts.py +++ b/tests/components/microsoft/test_tts.py @@ -8,18 +8,13 @@ from pycsspeechtts import pycsspeechtts import pytest from homeassistant.components import tts -from homeassistant.components.media_player import ( - ATTR_MEDIA_CONTENT_ID, - DOMAIN as DOMAIN_MP, - SERVICE_PLAY_MEDIA, -) +from homeassistant.components.media_player import ATTR_MEDIA_CONTENT_ID from homeassistant.components.microsoft.tts import SUPPORTED_LANGUAGES from homeassistant.config import async_process_ha_core_config from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import ServiceNotFound from homeassistant.setup import async_setup_component -from tests.common import async_mock_service from tests.components.tts.common import retrieve_media 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 -@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) async def setup_internal_url(hass: HomeAssistant): """Set up internal url.""" @@ -58,7 +47,7 @@ async def test_service_say( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_tts, - calls: list[ServiceCall], + service_calls: list[ServiceCall], ) -> None: """Test service call say.""" @@ -77,9 +66,11 @@ async def test_service_say( blocking=True, ) - assert len(calls) == 1 + assert len(service_calls) == 2 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 ) @@ -102,7 +93,7 @@ async def test_service_say_en_gb_config( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_tts, - calls: list[ServiceCall], + service_calls: list[ServiceCall], ) -> None: """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, ) - assert len(calls) == 1 + assert len(service_calls) == 2 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 ) @@ -154,7 +147,7 @@ async def test_service_say_en_gb_service( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_tts, - calls: list[ServiceCall], + service_calls: list[ServiceCall], ) -> None: """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, ) - assert len(calls) == 1 + assert len(service_calls) == 2 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 ) @@ -201,7 +196,7 @@ async def test_service_say_fa_ir_config( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_tts, - calls: list[ServiceCall], + service_calls: list[ServiceCall], ) -> None: """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, ) - assert len(calls) == 1 + assert len(service_calls) == 2 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 ) @@ -253,7 +250,7 @@ async def test_service_say_fa_ir_service( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_tts, - calls: list[ServiceCall], + service_calls: list[ServiceCall], ) -> None: """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, ) - assert len(calls) == 1 + assert len(service_calls) == 2 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 ) @@ -317,9 +316,7 @@ def test_supported_languages() -> None: assert len(SUPPORTED_LANGUAGES) > 100 -async def test_invalid_language( - hass: HomeAssistant, mock_tts, calls: list[ServiceCall] -) -> None: +async def test_invalid_language(hass: HomeAssistant, mock_tts) -> None: """Test setup component with invalid language.""" await async_setup_component( hass, @@ -339,7 +336,6 @@ async def test_invalid_language( blocking=True, ) - assert len(calls) == 0 assert len(mock_tts.mock_calls) == 0 @@ -347,7 +343,7 @@ async def test_service_say_error( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_tts, - calls: list[ServiceCall], + service_calls: list[ServiceCall], ) -> None: """Test service call say with http error.""" mock_tts.return_value.speak.side_effect = pycsspeechtts.requests.HTTPError @@ -366,9 +362,11 @@ async def test_service_say_error( blocking=True, ) - assert len(calls) == 1 + assert len(service_calls) == 2 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 )