core/tests/components/panel_iframe/test_init.py

99 lines
3.1 KiB
Python
Raw Normal View History

2016-07-17 05:32:36 +00:00
"""The tests for the panel_iframe component."""
import unittest
from homeassistant import setup
2016-07-17 05:32:36 +00:00
from homeassistant.components import frontend
from tests.common import get_test_home_assistant
class TestPanelIframe(unittest.TestCase):
"""Test the panel_iframe component."""
def setUp(self):
2018-08-19 20:29:08 +00:00
"""Set up things to be run when tests are started."""
2016-07-17 05:32:36 +00:00
self.hass = get_test_home_assistant()
def tearDown(self):
2016-07-17 05:32:36 +00:00
"""Stop everything that was started."""
self.hass.stop()
def test_wrong_config(self):
"""Test setup with wrong configuration."""
to_try = [
2019-07-31 19:25:30 +00:00
{"invalid space": {"url": "https://home-assistant.io"}},
{"router": {"url": "not-a-url"}},
]
2016-07-17 05:32:36 +00:00
for conf in to_try:
assert not setup.setup_component(
2019-07-31 19:25:30 +00:00
self.hass, "panel_iframe", {"panel_iframe": conf}
)
2016-07-17 05:32:36 +00:00
def test_correct_config(self):
"""Test correct config."""
assert setup.setup_component(
2019-07-31 19:25:30 +00:00
self.hass,
"panel_iframe",
{
"panel_iframe": {
"router": {
"icon": "mdi:network-wireless",
"title": "Router",
"url": "http://192.168.1.1",
"require_admin": True,
2016-07-17 05:32:36 +00:00
},
2019-07-31 19:25:30 +00:00
"weather": {
"icon": "mdi:weather",
"title": "Weather",
"url": "https://www.wunderground.com/us/ca/san-diego",
"require_admin": True,
2016-07-17 05:32:36 +00:00
},
2019-07-31 19:25:30 +00:00
"api": {"icon": "mdi:weather", "title": "Api", "url": "/api"},
"ftp": {
"icon": "mdi:weather",
"title": "FTP",
"url": "ftp://some/ftp",
},
2019-07-31 19:25:30 +00:00
}
},
)
2016-07-17 05:32:36 +00:00
panels = self.hass.data[frontend.DATA_PANELS]
2019-07-31 19:25:30 +00:00
assert panels.get("router").to_response() == {
"component_name": "iframe",
"config": {"url": "http://192.168.1.1"},
"icon": "mdi:network-wireless",
"title": "Router",
"url_path": "router",
"require_admin": True,
2016-07-17 05:32:36 +00:00
}
2019-07-31 19:25:30 +00:00
assert panels.get("weather").to_response() == {
"component_name": "iframe",
"config": {"url": "https://www.wunderground.com/us/ca/san-diego"},
"icon": "mdi:weather",
"title": "Weather",
"url_path": "weather",
"require_admin": True,
2016-07-17 05:32:36 +00:00
}
2019-07-31 19:25:30 +00:00
assert panels.get("api").to_response() == {
"component_name": "iframe",
"config": {"url": "/api"},
"icon": "mdi:weather",
"title": "Api",
"url_path": "api",
"require_admin": False,
}
2019-07-31 19:25:30 +00:00
assert panels.get("ftp").to_response() == {
"component_name": "iframe",
"config": {"url": "ftp://some/ftp"},
"icon": "mdi:weather",
"title": "FTP",
"url_path": "ftp",
"require_admin": False,
}