1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Use !input instead of !placeholder (#43820)

* Use !input instead of !placeholder

* Update input name

* Lint

* Move tests around
This commit is contained in:
Paulus Schoutsen
2020-12-01 18:21:36 +01:00
committed by GitHub
parent 7d23ff6511
commit 1c9c99571e
23 changed files with 148 additions and 139 deletions

View File

@@ -4,7 +4,7 @@ import logging
import pytest
from homeassistant.components.blueprint import errors, models
from homeassistant.util.yaml import Placeholder
from homeassistant.util.yaml import Input
from tests.async_mock import patch
@@ -18,18 +18,16 @@ def blueprint_1():
"name": "Hello",
"domain": "automation",
"source_url": "https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml",
"input": {
"test-placeholder": {"name": "Name", "description": "Description"}
},
"input": {"test-input": {"name": "Name", "description": "Description"}},
},
"example": Placeholder("test-placeholder"),
"example": Input("test-input"),
}
)
@pytest.fixture
def blueprint_2():
"""Blueprint fixture with default placeholder."""
"""Blueprint fixture with default inputs."""
return models.Blueprint(
{
"blueprint": {
@@ -37,12 +35,12 @@ def blueprint_2():
"domain": "automation",
"source_url": "https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml",
"input": {
"test-placeholder": {"name": "Name", "description": "Description"},
"test-placeholder-default": {"default": "test"},
"test-input": {"name": "Name", "description": "Description"},
"test-input-default": {"default": "test"},
},
},
"example": Placeholder("test-placeholder"),
"example-default": Placeholder("test-placeholder-default"),
"example": Input("test-input"),
"example-default": Input("test-input-default"),
}
)
@@ -72,7 +70,7 @@ def test_blueprint_model_init():
"domain": "automation",
"input": {"something": None},
},
"trigger": {"platform": Placeholder("non-existing")},
"trigger": {"platform": Input("non-existing")},
}
)
@@ -83,11 +81,13 @@ def test_blueprint_properties(blueprint_1):
"name": "Hello",
"domain": "automation",
"source_url": "https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml",
"input": {"test-placeholder": {"name": "Name", "description": "Description"}},
"input": {"test-input": {"name": "Name", "description": "Description"}},
}
assert blueprint_1.domain == "automation"
assert blueprint_1.name == "Hello"
assert blueprint_1.placeholders == {"test-placeholder"}
assert blueprint_1.inputs == {
"test-input": {"name": "Name", "description": "Description"}
}
def test_blueprint_update_metadata():
@@ -140,13 +140,13 @@ def test_blueprint_inputs(blueprint_2):
{
"use_blueprint": {
"path": "bla",
"input": {"test-placeholder": 1, "test-placeholder-default": 12},
"input": {"test-input": 1, "test-input-default": 12},
},
"example-default": {"overridden": "via-config"},
},
)
inputs.validate()
assert inputs.inputs == {"test-placeholder": 1, "test-placeholder-default": 12}
assert inputs.inputs == {"test-input": 1, "test-input-default": 12}
assert inputs.async_substitute() == {
"example": 1,
"example-default": {"overridden": "via-config"},
@@ -159,7 +159,7 @@ def test_blueprint_inputs_validation(blueprint_1):
blueprint_1,
{"use_blueprint": {"path": "bla", "input": {"non-existing-placeholder": 1}}},
)
with pytest.raises(errors.MissingPlaceholder):
with pytest.raises(errors.MissingInput):
inputs.validate()
@@ -167,13 +167,13 @@ def test_blueprint_inputs_default(blueprint_2):
"""Test blueprint inputs."""
inputs = models.BlueprintInputs(
blueprint_2,
{"use_blueprint": {"path": "bla", "input": {"test-placeholder": 1}}},
{"use_blueprint": {"path": "bla", "input": {"test-input": 1}}},
)
inputs.validate()
assert inputs.inputs == {"test-placeholder": 1}
assert inputs.inputs == {"test-input": 1}
assert inputs.inputs_with_default == {
"test-placeholder": 1,
"test-placeholder-default": "test",
"test-input": 1,
"test-input-default": "test",
}
assert inputs.async_substitute() == {"example": 1, "example-default": "test"}
@@ -185,18 +185,18 @@ def test_blueprint_inputs_override_default(blueprint_2):
{
"use_blueprint": {
"path": "bla",
"input": {"test-placeholder": 1, "test-placeholder-default": "custom"},
"input": {"test-input": 1, "test-input-default": "custom"},
}
},
)
inputs.validate()
assert inputs.inputs == {
"test-placeholder": 1,
"test-placeholder-default": "custom",
"test-input": 1,
"test-input-default": "custom",
}
assert inputs.inputs_with_default == {
"test-placeholder": 1,
"test-placeholder-default": "custom",
"test-input": 1,
"test-input-default": "custom",
}
assert inputs.async_substitute() == {"example": 1, "example-default": "custom"}
@@ -238,7 +238,7 @@ async def test_domain_blueprints_inputs_from_config(domain_bps, blueprint_1):
with pytest.raises(errors.InvalidBlueprintInputs):
await domain_bps.async_inputs_from_config({"not-referencing": "use_blueprint"})
with pytest.raises(errors.MissingPlaceholder), patch.object(
with pytest.raises(errors.MissingInput), patch.object(
domain_bps, "async_get_blueprint", return_value=blueprint_1
):
await domain_bps.async_inputs_from_config(
@@ -247,10 +247,10 @@ async def test_domain_blueprints_inputs_from_config(domain_bps, blueprint_1):
with patch.object(domain_bps, "async_get_blueprint", return_value=blueprint_1):
inputs = await domain_bps.async_inputs_from_config(
{"use_blueprint": {"path": "bla.yaml", "input": {"test-placeholder": None}}}
{"use_blueprint": {"path": "bla.yaml", "input": {"test-input": None}}}
)
assert inputs.blueprint is blueprint_1
assert inputs.inputs == {"test-placeholder": None}
assert inputs.inputs == {"test-input": None}
async def test_domain_blueprints_add_blueprint(domain_bps, blueprint_1):