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