Consolidate frontend (#9915)
* Consolidate frontend * Remove home-assistant-polymer submodule * Convert to using a pypi package for frontend * fix release script * Lint * Remove unused file * Remove frontend related scripts * Move hass_frontend to frontend REQUIREMENTS * Fix tests * lint * Address comments * Lint + fix tests in py34 * Fix py34 tests again * fix typo
This commit is contained in:
1 parent
29fb65b224
commit
2bdad5388b
169 files changed
+372
-5396
No files matched your search
@@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.frontend import (
|
||||
DOMAIN, ATTR_THEMES, ATTR_EXTRA_HTML_URL, DATA_PANELS, register_panel)
|
||||
DOMAIN, CONF_THEMES, CONF_EXTRA_HTML_URL, DATA_PANELS)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -22,7 +22,7 @@ def mock_http_client_with_themes(hass, test_client):
|
||||
"""Start the Hass HTTP component."""
|
||||
hass.loop.run_until_complete(async_setup_component(hass, 'frontend', {
|
||||
DOMAIN: {
|
||||
ATTR_THEMES: {
|
||||
CONF_THEMES: {
|
||||
'happy': {
|
||||
'primary-color': 'red'
|
||||
}
|
||||
@@ -36,7 +36,7 @@ def mock_http_client_with_urls(hass, test_client):
|
||||
"""Start the Hass HTTP component."""
|
||||
hass.loop.run_until_complete(async_setup_component(hass, 'frontend', {
|
||||
DOMAIN: {
|
||||
ATTR_EXTRA_HTML_URL: ["https://domain.com/my_extra_url.html"]
|
||||
CONF_EXTRA_HTML_URL: ["https://domain.com/my_extra_url.html"]
|
||||
}}))
|
||||
return hass.loop.run_until_complete(test_client(hass.http.app))
|
||||
|
||||
@@ -133,7 +133,7 @@ def test_themes_reload_themes(hass, mock_http_client_with_themes):
|
||||
"""Test frontend.reload_themes service."""
|
||||
with patch('homeassistant.components.frontend.load_yaml_config_file',
|
||||
return_value={DOMAIN: {
|
||||
ATTR_THEMES: {
|
||||
CONF_THEMES: {
|
||||
'sad': {'primary-color': 'blue'}
|
||||
}}}):
|
||||
yield from hass.services.async_call(DOMAIN, 'set_theme',
|
||||
@@ -168,15 +168,7 @@ def test_extra_urls(mock_http_client_with_urls):
|
||||
@asyncio.coroutine
|
||||
def test_panel_without_path(hass):
|
||||
"""Test panel registration without file path."""
|
||||
register_panel(hass, 'test_component', 'nonexistant_file')
|
||||
assert hass.data[DATA_PANELS] == {}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_panel_with_url(hass):
|
||||
"""Test panel registration without file path."""
|
||||
register_panel(hass, 'test_component', None, url='some_url')
|
||||
assert hass.data[DATA_PANELS] == {
|
||||
'test_component': {'component_name': 'test_component',
|
||||
'url': 'some_url',
|
||||
'url_path': 'test_component'}}
|
||||
yield from hass.components.frontend.async_register_panel(
|
||||
'test_component', 'nonexistant_file')
|
||||
yield from async_setup_component(hass, 'frontend', {})
|
||||
assert 'test_component' not in hass.data[DATA_PANELS]
|
||||
@@ -3,7 +3,6 @@
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import sun
|
||||
import homeassistant.core as ha
|
||||
@@ -32,10 +31,8 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
init_recorder_component(self.hass) # Force an in memory DB
|
||||
mock_http_component(self.hass)
|
||||
self.hass.config.components |= set(['frontend', 'recorder', 'api'])
|
||||
with patch('homeassistant.components.logbook.'
|
||||
'register_built_in_panel'):
|
||||
assert setup_component(self.hass, logbook.DOMAIN,
|
||||
self.EMPTY_CONFIG)
|
||||
assert setup_component(self.hass, logbook.DOMAIN,
|
||||
self.EMPTY_CONFIG)
|
||||
self.hass.start()
|
||||
|
||||
def tearDown(self):
|
||||
|
||||
@@ -1,89 +1,79 @@
|
||||
"""The tests for the panel_custom component."""
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
import asyncio
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import setup
|
||||
from homeassistant.components import panel_custom
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
from tests.common import mock_coro, mock_component
|
||||
|
||||
|
||||
@patch('homeassistant.components.frontend.setup',
|
||||
autospec=True, return_value=True)
|
||||
class TestPanelCustom(unittest.TestCase):
|
||||
"""Test the panel_custom component."""
|
||||
@pytest.fixture
|
||||
def mock_register(hass):
|
||||
"""Mock the frontend component being loaded and yield register method."""
|
||||
mock_component(hass, 'frontend')
|
||||
with patch('homeassistant.components.frontend.async_register_panel',
|
||||
return_value=mock_coro()) as mock_register:
|
||||
yield mock_register
|
||||
|
||||
def setup_method(self, method):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
shutil.rmtree(self.hass.config.path(panel_custom.PANEL_DIR),
|
||||
ignore_errors=True)
|
||||
@asyncio.coroutine
|
||||
def test_webcomponent_custom_path_not_found(hass, mock_register):
|
||||
"""Test if a web component is found in config panels dir."""
|
||||
filename = 'mock.file'
|
||||
|
||||
@patch('homeassistant.components.panel_custom.register_panel')
|
||||
def test_webcomponent_in_panels_dir(self, mock_register, _mock_setup):
|
||||
"""Test if a web component is found in config panels dir."""
|
||||
config = {
|
||||
'panel_custom': {
|
||||
'name': 'todomvc',
|
||||
}
|
||||
config = {
|
||||
'panel_custom': {
|
||||
'name': 'todomvc',
|
||||
'webcomponent_path': filename,
|
||||
'sidebar_title': 'Sidebar Title',
|
||||
'sidebar_icon': 'mdi:iconicon',
|
||||
'url_path': 'nice_url',
|
||||
'config': 5,
|
||||
}
|
||||
}
|
||||
|
||||
assert not setup.setup_component(self.hass, 'panel_custom', config)
|
||||
with patch('os.path.isfile', Mock(return_value=False)):
|
||||
result = yield from setup.async_setup_component(
|
||||
hass, 'panel_custom', config
|
||||
)
|
||||
assert not result
|
||||
assert not mock_register.called
|
||||
|
||||
path = self.hass.config.path(panel_custom.PANEL_DIR)
|
||||
os.mkdir(path)
|
||||
self.hass.data.pop(setup.DATA_SETUP)
|
||||
|
||||
with open(os.path.join(path, 'todomvc.html'), 'a'):
|
||||
assert setup.setup_component(self.hass, 'panel_custom', config)
|
||||
@asyncio.coroutine
|
||||
def test_webcomponent_custom_path(hass, mock_register):
|
||||
"""Test if a web component is found in config panels dir."""
|
||||
filename = 'mock.file'
|
||||
|
||||
config = {
|
||||
'panel_custom': {
|
||||
'name': 'todomvc',
|
||||
'webcomponent_path': filename,
|
||||
'sidebar_title': 'Sidebar Title',
|
||||
'sidebar_icon': 'mdi:iconicon',
|
||||
'url_path': 'nice_url',
|
||||
'config': 5,
|
||||
}
|
||||
}
|
||||
|
||||
with patch('os.path.isfile', Mock(return_value=True)):
|
||||
with patch('os.access', Mock(return_value=True)):
|
||||
result = yield from setup.async_setup_component(
|
||||
hass, 'panel_custom', config
|
||||
)
|
||||
assert result
|
||||
|
||||
assert mock_register.called
|
||||
|
||||
@patch('homeassistant.components.panel_custom.register_panel')
|
||||
def test_webcomponent_custom_path(self, mock_register, _mock_setup):
|
||||
"""Test if a web component is found in config panels dir."""
|
||||
filename = 'mock.file'
|
||||
args = mock_register.mock_calls[0][1]
|
||||
assert args == (hass, 'todomvc', filename)
|
||||
|
||||
config = {
|
||||
'panel_custom': {
|
||||
'name': 'todomvc',
|
||||
'webcomponent_path': filename,
|
||||
'sidebar_title': 'Sidebar Title',
|
||||
'sidebar_icon': 'mdi:iconicon',
|
||||
'url_path': 'nice_url',
|
||||
kwargs = mock_register.mock_calls[0][2]
|
||||
assert kwargs == {
|
||||
'config': 5,
|
||||
'url_path': 'nice_url',
|
||||
'sidebar_icon': 'mdi:iconicon',
|
||||
'sidebar_title': 'Sidebar Title'
|
||||
}
|
||||
}
|
||||
|
||||
with patch('os.path.isfile', Mock(return_value=False)):
|
||||
assert not setup.setup_component(
|
||||
self.hass, 'panel_custom', config
|
||||
)
|
||||
assert not mock_register.called
|
||||
|
||||
self.hass.data.pop(setup.DATA_SETUP)
|
||||
|
||||
with patch('os.path.isfile', Mock(return_value=True)):
|
||||
with patch('os.access', Mock(return_value=True)):
|
||||
assert setup.setup_component(
|
||||
self.hass, 'panel_custom', config
|
||||
)
|
||||
|
||||
assert mock_register.called
|
||||
|
||||
args = mock_register.mock_calls[0][1]
|
||||
assert args == (self.hass, 'todomvc', filename)
|
||||
|
||||
kwargs = mock_register.mock_calls[0][2]
|
||||
assert kwargs == {
|
||||
'config': 5,
|
||||
'url_path': 'nice_url',
|
||||
'sidebar_icon': 'mdi:iconicon',
|
||||
'sidebar_title': 'Sidebar Title'
|
||||
}
|
||||
@@ -33,8 +33,8 @@ class TestPanelIframe(unittest.TestCase):
|
||||
'panel_iframe': conf
|
||||
})
|
||||
|
||||
@patch.dict('homeassistant.components.frontend.FINGERPRINTS', {
|
||||
'panels/ha-panel-iframe.html': 'md5md5'})
|
||||
@patch.dict('hass_frontend.FINGERPRINTS',
|
||||
{'panels/ha-panel-iframe.html': 'md5md5'})
|
||||
def test_correct_config(self):
|
||||
"""Test correct config."""
|
||||
assert setup.setup_component(
|
||||
@@ -53,20 +53,22 @@ class TestPanelIframe(unittest.TestCase):
|
||||
},
|
||||
})
|
||||
|
||||
assert self.hass.data[frontend.DATA_PANELS].get('router') == {
|
||||
panels = self.hass.data[frontend.DATA_PANELS]
|
||||
|
||||
assert panels.get('router').as_dict() == {
|
||||
'component_name': 'iframe',
|
||||
'config': {'url': 'http://192.168.1.1'},
|
||||
'icon': 'mdi:network-wireless',
|
||||
'title': 'Router',
|
||||
'url': '/frontend/panels/iframe-md5md5.html',
|
||||
'url': '/static/panels/ha-panel-iframe-md5md5.html',
|
||||
'url_path': 'router'
|
||||
}
|
||||
|
||||
assert self.hass.data[frontend.DATA_PANELS].get('weather') == {
|
||||
assert panels.get('weather').as_dict() == {
|
||||
'component_name': 'iframe',
|
||||
'config': {'url': 'https://www.wunderground.com/us/ca/san-diego'},
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'Weather',
|
||||
'url': '/frontend/panels/iframe-md5md5.html',
|
||||
'url': '/static/panels/ha-panel-iframe-md5md5.html',
|
||||
'url_path': 'weather',
|
||||
}
|
||||
@@ -288,8 +288,8 @@ def test_get_config(hass, websocket_client):
|
||||
@asyncio.coroutine
|
||||
def test_get_panels(hass, websocket_client):
|
||||
"""Test get_panels command."""
|
||||
frontend.register_built_in_panel(hass, 'map', 'Map',
|
||||
'mdi:account-location')
|
||||
yield from hass.components.frontend.async_register_built_in_panel(
|
||||
'map', 'Map', 'mdi:account-location')
|
||||
|
||||
websocket_client.send_json({
|
||||
'id': 5,
|
||||
@@ -300,7 +300,8 @@ def test_get_panels(hass, websocket_client):
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success']
|
||||
assert msg['result'] == hass.data[frontend.DATA_PANELS]
|
||||
assert msg['result'] == {url: panel.as_dict() for url, panel
|
||||
in hass.data[frontend.DATA_PANELS].items()}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
Reference in new issue
Block a user