mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Added template rendering to shell_command component (#2268)
* Added template rendering to `shell_command` component * Security upgrades to template rendering in shell_command. * Added new unit tests for shell_command templates. Better failure when template is invalid in shell_command
This commit is contained in:
committed by
Paulus Schoutsen
parent
b646accf87
commit
2882f05f2c
@@ -51,6 +51,30 @@ class TestShellCommand(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
def test_template_render_no_template(self):
|
||||
"""Ensure shell_commands without templates get rendered properly."""
|
||||
cmd, shell = shell_command._parse_command(self.hass, 'ls /bin', {})
|
||||
self.assertTrue(shell)
|
||||
self.assertEqual(cmd, 'ls /bin')
|
||||
|
||||
def test_template_render(self):
|
||||
"""Ensure shell_commands with templates get rendered properly."""
|
||||
self.hass.states.set('sensor.test_state', 'Works')
|
||||
cmd, shell = shell_command._parse_command(
|
||||
self.hass,
|
||||
'ls /bin {{ states.sensor.test_state.state }}', {}
|
||||
)
|
||||
self.assertFalse(shell, False)
|
||||
self.assertEqual(cmd[-1], 'Works')
|
||||
|
||||
def test_invalid_template_fails(self):
|
||||
"""Test that shell_commands with invalid templates fail."""
|
||||
cmd, _shell = shell_command._parse_command(
|
||||
self.hass,
|
||||
'ls /bin {{ states. .test_state.state }}', {}
|
||||
)
|
||||
self.assertEqual(cmd, None)
|
||||
|
||||
@patch('homeassistant.components.shell_command.subprocess.call',
|
||||
side_effect=SubprocessError)
|
||||
@patch('homeassistant.components.shell_command._LOGGER.error')
|
||||
|
||||
Reference in New Issue
Block a user