Report unserializable data in websocket (#34072)

* Report unserializable data in websocket

* Fix tests

* log types too
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-13 23:46:41 -07:00
1 parent 45beb3c6e4
commit d93c09327a
4 files changed
+105 -28

No files matched your search

@@ -64,3 +64,19 @@ async def test_pending_msg_peak(hass, mock_low_peak, hass_ws_client, caplog):
assert msg.type == WSMsgType.close
assert "Client unable to keep up with pending messages" in caplog.text
async def test_non_json_message(hass, websocket_client, caplog):
"""Test trying to serialze non JSON objects."""
bad_data = object()
hass.states.async_set("test_domain.entity", "testing", {"bad": bad_data})
await websocket_client.send_json({"id": 5, "type": "get_states"})
msg = await websocket_client.receive_json()
assert msg["id"] == 5
assert msg["type"] == const.TYPE_RESULT
assert not msg["success"]
assert (
f"Unable to serialize to JSON. Bad data found at $.result[0](state: test_domain.entity).attributes.bad={bad_data}(<class 'object'>"
in caplog.text
)