1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-13 15:30:03 +00:00
Files
.github
config
docs
homeassistant
script
tests
components
alarm_control_panel
automation
binary_sensor
camera
climate
cover
device_tracker
fan
light
lock
media_player
mqtt
notify
recorder
sensor
switch
weather
__init__.py
test_alexa.py
test_api.py
test_configurator.py
test_conversation.py
test_demo.py
test_device_sun_light_trigger.py
test_emulated_hue.py
test_frontend.py
test_graphite.py
test_group.py
test_history.py
test_http.py
test_influxdb.py
test_init.py
test_input_boolean.py
test_input_select.py
test_input_slider.py
test_introduction.py
test_logbook.py
test_logentries.py
test_logger.py
test_mqtt_eventstream.py
test_panel_custom.py
test_panel_iframe.py
test_persistent_notification.py
test_pilight.py
test_proximity.py
test_rfxtrx.py
test_scene.py
test_script.py
test_shell_command.py
test_sleepiq.py
test_splunk.py
test_statsd.py
test_sun.py
test_updater.py
test_weblink.py
test_zone.py
fixtures
helpers
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_core.py
test_loader.py
test_main.py
test_remote.py
virtualization
.coveragerc
.dockerignore
.gitignore
.gitmodules
.hound.yml
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
setup.cfg
setup.py
tox.ini
core/tests/components/test_panel_custom.py
Pascal Vizeli d5368f6f78 Async bootstrap / component init ()
* Async bootstrap

* Adress comments

* Fix tests

* More fixes

* Tests fixes
2016-10-27 00:16:23 -07:00

87 lines
2.9 KiB
Python

"""The tests for the panel_custom component."""
import os
import shutil
import unittest
from unittest.mock import Mock, patch
from homeassistant import bootstrap
from homeassistant.components import panel_custom
from tests.common import get_test_home_assistant
@patch('homeassistant.components.frontend.setup',
autospec=True, return_value=True)
class TestPanelCustom(unittest.TestCase):
"""Test the panel_custom component."""
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)
@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',
}
}
assert not bootstrap.setup_component(self.hass, 'panel_custom', config)
assert not mock_register.called
path = self.hass.config.path(panel_custom.PANEL_DIR)
os.mkdir(path)
with open(os.path.join(path, 'todomvc.html'), 'a'):
assert bootstrap.setup_component(self.hass, 'panel_custom', config)
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'
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=False)):
assert not bootstrap.setup_component(
self.hass, 'panel_custom', config
)
assert not mock_register.called
with patch('os.path.isfile', Mock(return_value=True)):
with patch('os.access', Mock(return_value=True)):
assert bootstrap.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'
}