1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

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:
Paulus Schoutsen
2017-10-24 19:36:27 -07:00
committed by GitHub
parent 29fb65b224
commit 2bdad5388b
169 changed files with 372 additions and 5396 deletions

View File

@@ -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'
}