mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Weblink - Allow relative urls in config (#11808)
* Allow relative url * Allow absolute urls in config schema * change after pylint build * Add tests and change error message * Change regex to check starting forward slash only * Change error message and const name
This commit is contained in:
parent
af5d0b3443
commit
74b0740e1c
@ -16,12 +16,15 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_ENTITIES = 'entities'
|
CONF_ENTITIES = 'entities'
|
||||||
|
CONF_RELATIVE_URL_ERROR_MSG = "Invalid relative URL. Absolute path required."
|
||||||
|
CONF_RELATIVE_URL_REGEX = r'\A/'
|
||||||
|
|
||||||
DOMAIN = 'weblink'
|
DOMAIN = 'weblink'
|
||||||
|
|
||||||
ENTITIES_SCHEMA = vol.Schema({
|
ENTITIES_SCHEMA = vol.Schema({
|
||||||
# pylint: disable=no-value-for-parameter
|
vol.Required(CONF_URL): vol.Any(
|
||||||
vol.Required(CONF_URL): vol.Url(),
|
vol.Match(CONF_RELATIVE_URL_REGEX, msg=CONF_RELATIVE_URL_ERROR_MSG),
|
||||||
|
cv.url),
|
||||||
vol.Required(CONF_NAME): cv.string,
|
vol.Required(CONF_NAME): cv.string,
|
||||||
vol.Optional(CONF_ICON): cv.icon,
|
vol.Optional(CONF_ICON): cv.icon,
|
||||||
})
|
})
|
||||||
|
@ -26,6 +26,71 @@ class TestComponentWeblink(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
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/'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
def test_entities_get_created(self):
|
def test_entities_get_created(self):
|
||||||
"""Test if new entity is created."""
|
"""Test if new entity is created."""
|
||||||
self.assertTrue(setup_component(self.hass, weblink.DOMAIN, {
|
self.assertTrue(setup_component(self.hass, weblink.DOMAIN, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user