2016-03-09 10:25:50 +01:00
|
|
|
"""The tests for the weblink component."""
|
2016-01-31 09:50:03 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from homeassistant.components import weblink
|
2019-12-09 14:47:53 +01:00
|
|
|
from homeassistant.setup import setup_component
|
2016-01-31 09:50:03 +01:00
|
|
|
|
2016-02-14 15:08:23 -08:00
|
|
|
from tests.common import get_test_home_assistant
|
2016-01-31 09:50:03 +01:00
|
|
|
|
2016-02-14 15:08:23 -08:00
|
|
|
|
|
|
|
class TestComponentWeblink(unittest.TestCase):
|
2016-03-09 10:25:50 +01:00
|
|
|
"""Test the Weblink component."""
|
2016-01-31 09:50:03 +01:00
|
|
|
|
|
|
|
def setUp(self):
|
2018-08-19 22:29:08 +02:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-02-14 15:08:23 -08:00
|
|
|
self.hass = get_test_home_assistant()
|
2016-01-31 09:50:03 +01:00
|
|
|
|
|
|
|
def tearDown(self):
|
2016-03-09 10:25:50 +01:00
|
|
|
"""Stop everything that was started."""
|
2016-01-31 09:50:03 +01:00
|
|
|
self.hass.stop()
|
|
|
|
|
2016-09-02 19:16:42 +02:00
|
|
|
def test_bad_config(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert not setup_component(
|
|
|
|
self.hass, "weblink", {"weblink": {"entities": [{}]}}
|
|
|
|
)
|
2016-09-02 19:16:42 +02:00
|
|
|
|
2018-01-27 07:30:39 +01:00
|
|
|
def test_bad_config_relative_url(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert not setup_component(
|
|
|
|
self.hass,
|
|
|
|
"weblink",
|
|
|
|
{
|
|
|
|
"weblink": {
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
weblink.CONF_NAME: "My router",
|
|
|
|
weblink.CONF_URL: "../states/group.bla",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-01-27 07:30:39 +01:00
|
|
|
|
|
|
|
def test_bad_config_relative_file(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert not setup_component(
|
|
|
|
self.hass,
|
|
|
|
"weblink",
|
|
|
|
{
|
|
|
|
"weblink": {
|
|
|
|
"entities": [
|
|
|
|
{weblink.CONF_NAME: "My group", weblink.CONF_URL: "group.bla"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-01-27 07:30:39 +01:00
|
|
|
|
|
|
|
def test_good_config_absolute_path(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"weblink",
|
|
|
|
{
|
|
|
|
"weblink": {
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
weblink.CONF_NAME: "My second URL",
|
|
|
|
weblink.CONF_URL: "/states/group.bla",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-01-27 07:30:39 +01:00
|
|
|
|
|
|
|
def test_good_config_path_short(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"weblink",
|
|
|
|
{
|
|
|
|
"weblink": {
|
|
|
|
"entities": [
|
|
|
|
{weblink.CONF_NAME: "My third URL", weblink.CONF_URL: "/states"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-01-27 07:30:39 +01:00
|
|
|
|
|
|
|
def test_good_config_path_directory(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"weblink",
|
|
|
|
{
|
|
|
|
"weblink": {
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
weblink.CONF_NAME: "My last URL",
|
|
|
|
weblink.CONF_URL: "/states/bla/",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-01-27 07:30:39 +01:00
|
|
|
|
2018-02-11 18:19:00 +01:00
|
|
|
def test_good_config_ftp_link(self):
|
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"weblink",
|
|
|
|
{
|
|
|
|
"weblink": {
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
weblink.CONF_NAME: "My FTP URL",
|
|
|
|
weblink.CONF_URL: "ftp://somehost/",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-02-11 18:19:00 +01:00
|
|
|
|
2016-02-14 15:08:23 -08:00
|
|
|
def test_entities_get_created(self):
|
2016-03-09 10:25:50 +01:00
|
|
|
"""Test if new entity is created."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
weblink.DOMAIN,
|
|
|
|
{
|
|
|
|
weblink.DOMAIN: {
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
weblink.CONF_NAME: "My router",
|
|
|
|
weblink.CONF_URL: "http://127.0.0.1/",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
state = self.hass.states.get("weblink.my_router")
|
2016-02-14 15:08:23 -08:00
|
|
|
|
|
|
|
assert state is not None
|
2019-07-31 12:25:30 -07:00
|
|
|
assert state.state == "http://127.0.0.1/"
|