mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
ElevenLabs invalid api key config flow testing (#133822)
This commit is contained in:
parent
c5fe25a001
commit
386a722393
@ -7,11 +7,7 @@ rules:
|
|||||||
appropriate-polling: done
|
appropriate-polling: done
|
||||||
brands: done
|
brands: done
|
||||||
common-modules: done
|
common-modules: done
|
||||||
config-flow-test-coverage:
|
config-flow-test-coverage: done
|
||||||
status: todo
|
|
||||||
comment: >
|
|
||||||
We should have every test end in either ABORT or CREATE_ENTRY.
|
|
||||||
test_invalid_api_key should assert the kind of error that is raised.
|
|
||||||
config-flow: done
|
config-flow: done
|
||||||
dependency-transparency: done
|
dependency-transparency: done
|
||||||
docs-actions: done
|
docs-actions: done
|
||||||
|
@ -24,14 +24,19 @@ def mock_setup_entry() -> Generator[AsyncMock]:
|
|||||||
yield mock_setup_entry
|
yield mock_setup_entry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def _client_mock():
|
||||||
def mock_async_client() -> Generator[AsyncMock]:
|
|
||||||
"""Override async ElevenLabs client."""
|
|
||||||
client_mock = AsyncMock()
|
client_mock = AsyncMock()
|
||||||
client_mock.voices.get_all.return_value = GetVoicesResponse(voices=MOCK_VOICES)
|
client_mock.voices.get_all.return_value = GetVoicesResponse(voices=MOCK_VOICES)
|
||||||
client_mock.models.get_all.return_value = MOCK_MODELS
|
client_mock.models.get_all.return_value = MOCK_MODELS
|
||||||
|
return client_mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_async_client() -> Generator[AsyncMock]:
|
||||||
|
"""Override async ElevenLabs client."""
|
||||||
with patch(
|
with patch(
|
||||||
"elevenlabs.AsyncElevenLabs", return_value=client_mock
|
"homeassistant.components.elevenlabs.config_flow.AsyncElevenLabs",
|
||||||
|
return_value=_client_mock(),
|
||||||
) as mock_async_client:
|
) as mock_async_client:
|
||||||
yield mock_async_client
|
yield mock_async_client
|
||||||
|
|
||||||
@ -41,7 +46,7 @@ def mock_async_client_fail() -> Generator[AsyncMock]:
|
|||||||
"""Override async ElevenLabs client."""
|
"""Override async ElevenLabs client."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.elevenlabs.config_flow.AsyncElevenLabs",
|
"homeassistant.components.elevenlabs.config_flow.AsyncElevenLabs",
|
||||||
return_value=AsyncMock(),
|
return_value=_client_mock(),
|
||||||
) as mock_async_client:
|
) as mock_async_client:
|
||||||
mock_async_client.side_effect = ApiError
|
mock_async_client.side_effect = ApiError
|
||||||
yield mock_async_client
|
yield mock_async_client
|
||||||
|
@ -73,10 +73,28 @@ async def test_invalid_api_key(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"]
|
assert result["errors"] == {"base": "invalid_api_key"}
|
||||||
|
|
||||||
mock_setup_entry.assert_not_called()
|
mock_setup_entry.assert_not_called()
|
||||||
|
|
||||||
|
# Reset the side effect
|
||||||
|
mock_async_client_fail.side_effect = None
|
||||||
|
|
||||||
|
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_options_flow_init(
|
async def test_options_flow_init(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user