core/tests/components/elevenlabs/test_config_flow.py
Simon 5fefa606b6
Add ElevenLabs text-to-speech integration (#115645)
* Add ElevenLabs text-to-speech integration

* Remove commented out code

* Use model_id instead of model_name for elevenlabs api

* Apply suggestions from code review

Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>

* Use async client instead of sync

* Add ElevenLabs code owner

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Set entity title to voice

* Rename to elevenlabs

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Allow multiple voices and options flow

* Sort default voice at beginning

* Rework config flow to include default model and reloading on options flow

* Add error to strings

* Add ElevenLabsData and suggestions from code review

* Shorten options and config flow

* Fix comments

* Fix comments

* Add wip

* Fix

* Cleanup

* Bump elevenlabs version

* Add data description

* Fix

---------

Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Michael Hansen <mike@rhasspy.org>
Co-authored-by: Joostlek <joostlek@outlook.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2024-07-31 21:31:09 +02:00

95 lines
2.7 KiB
Python

"""Test the ElevenLabs text-to-speech config flow."""
from unittest.mock import AsyncMock
from homeassistant.components.elevenlabs.const import (
CONF_MODEL,
CONF_VOICE,
DEFAULT_MODEL,
DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
async def test_user_step(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
mock_async_client: AsyncMock,
) -> None:
"""Test user step create entry result."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert not result["errors"]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_API_KEY: "api_key",
},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "ElevenLabs"
assert result["data"] == {
"api_key": "api_key",
}
assert result["options"] == {CONF_MODEL: DEFAULT_MODEL, CONF_VOICE: "voice1"}
mock_setup_entry.assert_called_once()
async def test_invalid_api_key(
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_async_client_fail: AsyncMock
) -> None:
"""Test user step with invalid api key."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert not result["errors"]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_API_KEY: "api_key",
},
)
assert result["type"] is FlowResultType.FORM
assert result["errors"]
mock_setup_entry.assert_not_called()
async def test_options_flow_init(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
mock_async_client: AsyncMock,
mock_entry: MockConfigEntry,
) -> None:
"""Test options flow init."""
mock_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(mock_entry.entry_id)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={CONF_MODEL: "model1", CONF_VOICE: "voice1"},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert mock_entry.options == {CONF_MODEL: "model1", CONF_VOICE: "voice1"}
mock_setup_entry.assert_called_once()