Config and service validation for shell_command component.
This commit is contained in:
parent
1deaf2fe8f
commit
d90f31bf6e
2 changed files with 28 additions and 26 deletions
|
@ -5,6 +5,7 @@ import unittest
|
|||
from unittest.mock import patch
|
||||
from subprocess import SubprocessError
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.components import shell_command
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
@ -25,11 +26,11 @@ class TestShellCommand(unittest.TestCase):
|
|||
"""Test if able to call a configured service."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, 'called.txt')
|
||||
self.assertTrue(shell_command.setup(self.hass, {
|
||||
'shell_command': {
|
||||
assert _setup_component(self.hass, shell_command.DOMAIN, {
|
||||
shell_command.DOMAIN: {
|
||||
'test_service': "date > {}".format(path)
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.services.call('shell_command', 'test_service',
|
||||
blocking=True)
|
||||
|
@ -38,16 +39,17 @@ class TestShellCommand(unittest.TestCase):
|
|||
|
||||
def test_config_not_dict(self):
|
||||
"""Test if config is not a dict."""
|
||||
self.assertFalse(shell_command.setup(self.hass, {
|
||||
'shell_command': ['some', 'weird', 'list']
|
||||
}))
|
||||
assert not _setup_component(self.hass, shell_command.DOMAIN, {
|
||||
shell_command.DOMAIN: ['some', 'weird', 'list']
|
||||
})
|
||||
|
||||
def test_config_not_valid_service_names(self):
|
||||
"""Test if config contains invalid service names."""
|
||||
self.assertFalse(shell_command.setup(self.hass, {
|
||||
'shell_command': {
|
||||
assert not _setup_component(self.hass, shell_command.DOMAIN, {
|
||||
shell_command.DOMAIN: {
|
||||
'this is invalid because space': 'touch bla.txt'
|
||||
}}))
|
||||
}
|
||||
})
|
||||
|
||||
@patch('homeassistant.components.shell_command.subprocess.call',
|
||||
side_effect=SubprocessError)
|
||||
|
@ -56,11 +58,11 @@ class TestShellCommand(unittest.TestCase):
|
|||
"""Test subprocess."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, 'called.txt')
|
||||
self.assertTrue(shell_command.setup(self.hass, {
|
||||
'shell_command': {
|
||||
assert _setup_component(self.hass, shell_command.DOMAIN, {
|
||||
shell_command.DOMAIN: {
|
||||
'test_service': "touch {}".format(path)
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.services.call('shell_command', 'test_service',
|
||||
blocking=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue