Add test for WS conversation/agent/info (#91652)
This commit is contained in:
parent
9092f6a60f
commit
b5ab83def4
3 changed files with 69 additions and 0 deletions
|
@ -18,6 +18,11 @@ class MockAgent(conversation.AbstractConversationAgent):
|
|||
self.calls = []
|
||||
self.response = "Test response"
|
||||
|
||||
@property
|
||||
def attribution(self) -> conversation.Attribution | None:
|
||||
"""Return the attribution."""
|
||||
return {"name": "Mock assistant", "url": "https://assist.me"}
|
||||
|
||||
@property
|
||||
def supported_languages(self) -> list[str]:
|
||||
"""Return a list of supported languages."""
|
||||
|
|
|
@ -79,3 +79,30 @@
|
|||
]),
|
||||
})
|
||||
# ---
|
||||
# name: test_ws_get_agent_info
|
||||
dict({
|
||||
'attribution': dict({
|
||||
'name': 'Mock assistant',
|
||||
'url': 'https://assist.me',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
# name: test_ws_get_agent_info.1
|
||||
dict({
|
||||
'attribution': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_ws_get_agent_info.2
|
||||
dict({
|
||||
'attribution': dict({
|
||||
'name': 'Mock assistant',
|
||||
'url': 'https://assist.me',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
# name: test_ws_get_agent_info.3
|
||||
dict({
|
||||
'code': 'invalid_format',
|
||||
'message': "invalid agent ID for dictionary value @ data['agent_id']. Got 'not_exist'",
|
||||
})
|
||||
# ---
|
||||
|
|
|
@ -1624,3 +1624,40 @@ async def test_get_agent_info(
|
|||
assert conversation.async_get_agent_info(hass, "homeassistant") == snapshot
|
||||
assert conversation.async_get_agent_info(hass, mock_agent.agent_id) == snapshot
|
||||
assert conversation.async_get_agent_info(hass, "not exist") is None
|
||||
|
||||
|
||||
async def test_ws_get_agent_info(
|
||||
hass: HomeAssistant,
|
||||
init_components,
|
||||
mock_agent,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test get agent info."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json_auto_id({"type": "conversation/agent/info"})
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == snapshot
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{"type": "conversation/agent/info", "agent_id": "homeassistant"}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == snapshot
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{"type": "conversation/agent/info", "agent_id": mock_agent.agent_id}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == snapshot
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{"type": "conversation/agent/info", "agent_id": "not_exist"}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == snapshot
|
||||
|
|
Loading…
Add table
Reference in a new issue