mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 12:50:45 -04:00
Test the ElevenLabs invalid_api_key code fallback (#187563)
Signed-off-by: Avi Miller <me@dje.li> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6aebf8d2c4
commit
9f84a2c0ed
@@ -107,6 +107,29 @@ def mock_async_client_api_key_id_error() -> Generator[AsyncMock]:
|
||||
yield mock_async_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_async_client_invalid_key_code_error() -> Generator[AsyncMock]:
|
||||
"""Override async ElevenLabs client with an invalid key reported only by code."""
|
||||
client_mock = _client_mock()
|
||||
api_error = ApiError()
|
||||
api_error.body = {
|
||||
"detail": {
|
||||
"type": "authentication_error",
|
||||
"code": "invalid_api_key",
|
||||
"status": "api_key_revoked",
|
||||
"message": "API key has been revoked",
|
||||
}
|
||||
}
|
||||
client_mock.models.list.side_effect = api_error
|
||||
client_mock.voices.get_all.side_effect = api_error
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.elevenlabs.config_flow.AsyncElevenLabs",
|
||||
return_value=client_mock,
|
||||
) as mock_async_client:
|
||||
yield mock_async_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_async_client_voices_error() -> Generator[AsyncMock]:
|
||||
"""Override async ElevenLabs client with ApiError side effect."""
|
||||
|
||||
@@ -72,6 +72,11 @@ async def test_user_step(
|
||||
"api_key_id_used",
|
||||
id="api_key_id_used",
|
||||
),
|
||||
pytest.param(
|
||||
"mock_async_client_invalid_key_code_error",
|
||||
"invalid_api_key",
|
||||
id="invalid_api_key_code",
|
||||
),
|
||||
pytest.param(
|
||||
"mock_async_client_connect_error", "cannot_connect", id="cannot_connect"
|
||||
),
|
||||
@@ -339,6 +344,11 @@ async def test_reauth_flow(
|
||||
"api_key_id_used",
|
||||
id="api_key_id_used",
|
||||
),
|
||||
pytest.param(
|
||||
"mock_async_client_invalid_key_code_error",
|
||||
"invalid_api_key",
|
||||
id="invalid_api_key_code",
|
||||
),
|
||||
pytest.param("mock_async_client_voices_error", "unknown", id="unknown"),
|
||||
pytest.param(
|
||||
"mock_async_client_connect_error", "cannot_connect", id="cannot_connect"
|
||||
|
||||
Reference in New Issue
Block a user