mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
cover
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
"""Test decorators."""
|
"""Test decorators."""
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import http, websocket_api
|
from homeassistant.components import http, websocket_api
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@@ -31,9 +33,16 @@ async def test_async_response_request_context(
|
|||||||
def get_request(hass, connection, msg):
|
def get_request(hass, connection, msg):
|
||||||
handle_request(http.current_request.get(), connection, msg)
|
handle_request(http.current_request.get(), connection, msg)
|
||||||
|
|
||||||
|
@websocket_api.websocket_command(
|
||||||
|
{"type": "test-get-request-with-arg", vol.Required("arg"): str}
|
||||||
|
)
|
||||||
|
def get_with_arg_request(hass, connection, msg):
|
||||||
|
handle_request(http.current_request.get(), connection, msg)
|
||||||
|
|
||||||
websocket_api.async_register_command(hass, executor_get_request)
|
websocket_api.async_register_command(hass, executor_get_request)
|
||||||
websocket_api.async_register_command(hass, async_get_request)
|
websocket_api.async_register_command(hass, async_get_request)
|
||||||
websocket_api.async_register_command(hass, get_request)
|
websocket_api.async_register_command(hass, get_request)
|
||||||
|
websocket_api.async_register_command(hass, get_with_arg_request)
|
||||||
|
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{
|
{
|
||||||
@@ -71,6 +80,48 @@ async def test_async_response_request_context(
|
|||||||
assert not msg["success"]
|
assert not msg["success"]
|
||||||
assert msg["error"]["code"] == "not_found"
|
assert msg["error"]["code"] == "not_found"
|
||||||
|
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"type": "test-get-request-with-arg",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
assert msg["id"] == 8
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == "invalid_format"
|
||||||
|
assert (
|
||||||
|
msg["error"]["message"] == "required key not provided @ data['arg']. Got None"
|
||||||
|
)
|
||||||
|
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"type": "test-get-request-with-arg",
|
||||||
|
"arg": "dog",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
assert msg["id"] == 9
|
||||||
|
assert msg["success"]
|
||||||
|
assert msg["result"] == "/api/websocket"
|
||||||
|
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": -1,
|
||||||
|
"type": "test-get-request-with-arg",
|
||||||
|
"arg": "dog",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
assert msg["id"] == -1
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == "invalid_format"
|
||||||
|
assert msg["error"]["message"] == "Message incorrectly formatted."
|
||||||
|
|
||||||
|
|
||||||
async def test_supervisor_only(hass: HomeAssistant, websocket_client) -> None:
|
async def test_supervisor_only(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test that only the Supervisor can make requests."""
|
"""Test that only the Supervisor can make requests."""
|
||||||
|
Reference in New Issue
Block a user