mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
coverage
This commit is contained in:
parent
ed8e8cbdef
commit
7c103ca9ae
@ -67,6 +67,8 @@ class CommandLineNotificationService(BaseNotificationService):
|
||||
if rendered_args != args:
|
||||
command = f"{prog} {rendered_args}"
|
||||
|
||||
LOGGER.debug("Running command: %s, with message: %s", command, message)
|
||||
|
||||
with subprocess.Popen( # noqa: S602 # shell by design
|
||||
command,
|
||||
universal_newlines=True,
|
||||
|
@ -100,6 +100,35 @@ async def test_command_line_output(hass: HomeAssistant) -> None:
|
||||
assert message == await hass.async_add_executor_job(Path(filename).read_text)
|
||||
|
||||
|
||||
async def test_command_line_output_single_command(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test the command line output."""
|
||||
|
||||
await setup.async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
"command_line": [
|
||||
{
|
||||
"notify": {
|
||||
"command": "echo",
|
||||
"name": "Test3",
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.services.has_service(NOTIFY_DOMAIN, "test3")
|
||||
|
||||
await hass.services.async_call(
|
||||
NOTIFY_DOMAIN, "test3", {"message": "test message"}, blocking=True
|
||||
)
|
||||
assert "Running command: echo, with message: test message" in caplog.text
|
||||
|
||||
|
||||
async def test_command_template(hass: HomeAssistant) -> None:
|
||||
"""Test the command line output using template as command."""
|
||||
|
||||
@ -131,6 +160,40 @@ async def test_command_template(hass: HomeAssistant) -> None:
|
||||
assert message == await hass.async_add_executor_job(Path(filename).read_text)
|
||||
|
||||
|
||||
async def test_command_incorrect_template(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test the command line output using template as command which isn't working."""
|
||||
|
||||
message = "one, two, testing, testing"
|
||||
await setup.async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
"command_line": [
|
||||
{
|
||||
"notify": {
|
||||
"command": "cat > {{ this template doesn't parse ",
|
||||
"name": "Test3",
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.services.has_service(NOTIFY_DOMAIN, "test3")
|
||||
|
||||
await hass.services.async_call(
|
||||
NOTIFY_DOMAIN, "test3", {"message": message}, blocking=True
|
||||
)
|
||||
|
||||
assert (
|
||||
"Error rendering command template: TemplateSyntaxError: expected token"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"get_config",
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user