Extract lovelace to it's own component (#16816)
* Extract lovelace to it's own component * Lint * Update comment * Lint * Lint
This commit is contained in:
parent
354c8f3409
commit
e78f4d1b65
5 changed files with 173 additions and 93 deletions
120
tests/components/lovelace/test_init.py
Normal file
120
tests/components/lovelace/test_init.py
Normal file
|
@ -0,0 +1,120 @@
|
|||
"""Test the Lovelace initialization."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import websocket_api as wapi
|
||||
|
||||
|
||||
async def test_deprecated_lovelace_ui(hass, hass_ws_client):
|
||||
"""Test lovelace_ui command."""
|
||||
await async_setup_component(hass, 'lovelace')
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch('homeassistant.components.lovelace.load_yaml',
|
||||
return_value={'hello': 'world'}):
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'frontend/lovelace_config',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success']
|
||||
assert msg['result'] == {'hello': 'world'}
|
||||
|
||||
|
||||
async def test_deprecated_lovelace_ui_not_found(hass, hass_ws_client):
|
||||
"""Test lovelace_ui command cannot find file."""
|
||||
await async_setup_component(hass, 'lovelace')
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch('homeassistant.components.lovelace.load_yaml',
|
||||
side_effect=FileNotFoundError):
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'frontend/lovelace_config',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success'] is False
|
||||
assert msg['error']['code'] == 'file_not_found'
|
||||
|
||||
|
||||
async def test_deprecated_lovelace_ui_load_err(hass, hass_ws_client):
|
||||
"""Test lovelace_ui command cannot find file."""
|
||||
await async_setup_component(hass, 'lovelace')
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch('homeassistant.components.lovelace.load_yaml',
|
||||
side_effect=HomeAssistantError):
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'frontend/lovelace_config',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success'] is False
|
||||
assert msg['error']['code'] == 'load_error'
|
||||
|
||||
|
||||
async def test_lovelace_ui(hass, hass_ws_client):
|
||||
"""Test lovelace_ui command."""
|
||||
await async_setup_component(hass, 'lovelace')
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch('homeassistant.components.lovelace.load_yaml',
|
||||
return_value={'hello': 'world'}):
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'lovelace/config',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success']
|
||||
assert msg['result'] == {'hello': 'world'}
|
||||
|
||||
|
||||
async def test_lovelace_ui_not_found(hass, hass_ws_client):
|
||||
"""Test lovelace_ui command cannot find file."""
|
||||
await async_setup_component(hass, 'lovelace')
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch('homeassistant.components.lovelace.load_yaml',
|
||||
side_effect=FileNotFoundError):
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'lovelace/config',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success'] is False
|
||||
assert msg['error']['code'] == 'file_not_found'
|
||||
|
||||
|
||||
async def test_lovelace_ui_load_err(hass, hass_ws_client):
|
||||
"""Test lovelace_ui command cannot find file."""
|
||||
await async_setup_component(hass, 'lovelace')
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
with patch('homeassistant.components.lovelace.load_yaml',
|
||||
side_effect=HomeAssistantError):
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'lovelace/config',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success'] is False
|
||||
assert msg['error']['code'] == 'load_error'
|
Loading…
Add table
Add a link
Reference in a new issue