Test conversation WS API (#84466)

This commit is contained in:
Paulus Schoutsen 2022-12-22 20:19:37 -05:00 committed by GitHub
parent 6234190cfe
commit 96533e4c8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 2 deletions

View file

@ -89,7 +89,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
{
"type": "conversation/process",
"text": str,
vol.Optional("conversation_id"): str,
vol.Optional("conversation_id"): vol.Any(str, None),
vol.Optional("language"): str,
}
)

View file

@ -1,6 +1,6 @@
"""The tests for the Conversation component."""
from http import HTTPStatus
from unittest.mock import patch
from unittest.mock import ANY, patch
import pytest
@ -481,3 +481,55 @@ async def test_custom_agent(hass, hass_client, hass_admin_user):
assert calls[0][1].user_id == hass_admin_user.id
assert calls[0][2] == "test-conv-id"
assert calls[0][3] == "test-language"
@pytest.mark.parametrize(
"payload",
[
{
"text": "Test Text",
},
{
"text": "Test Text",
"language": "test-language",
},
{
"text": "Test Text",
"conversation_id": "test-conv-id",
},
{
"text": "Test Text",
"conversation_id": None,
},
{
"text": "Test Text",
"conversation_id": "test-conv-id",
"language": "test-language",
},
],
)
async def test_ws_api(hass, hass_ws_client, payload):
"""Test the Websocket conversation API."""
assert await async_setup_component(hass, "conversation", {})
client = await hass_ws_client(hass)
await client.send_json({"id": 5, "type": "conversation/process", **payload})
msg = await client.receive_json()
assert msg["success"]
assert msg["result"] == {
"response": {
"response_type": "error",
"card": {},
"speech": {
"plain": {
"extra_data": None,
"speech": "Sorry, I didn't understand that",
}
},
"language": payload.get("language", hass.config.language),
"data": {"code": "no_intent_match"},
},
"conversation_id": payload.get("conversation_id") or ANY,
}