2016-07-17 05:32:36 +00:00
|
|
|
"""The tests for the panel_iframe component."""
|
|
|
|
import unittest
|
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
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."""
|
|
|
|
|
2018-01-27 06:31:40 +00:00
|
|
|
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()
|
|
|
|
|
2018-01-27 06:31:40 +00:00
|
|
|
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:
|
2017-03-05 09:41:54 +00:00
|
|
|
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."""
|
2017-03-05 09:41:54 +00:00
|
|
|
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",
|
2018-01-27 06:31:40 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2016-07-17 05:32:36 +00:00
|
|
|
|
2017-10-25 02:36:27 +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
|
|
|
}
|
2018-01-27 06:31:40 +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,
|
2018-01-27 06:31:40 +00:00
|
|
|
}
|
2018-02-11 17:19:31 +00:00
|
|
|
|
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,
|
2018-02-11 17:19:31 +00:00
|
|
|
}
|