68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
"""Test selectors."""
|
|
import pytest
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.helpers import selector
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"schema",
|
|
(
|
|
{"device": None},
|
|
{"entity": None},
|
|
),
|
|
)
|
|
def test_valid_base_schema(schema):
|
|
"""Test base schema validation."""
|
|
selector.validate_selector(schema)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"schema",
|
|
(
|
|
{},
|
|
{"non_existing": {}},
|
|
# Two keys
|
|
{"device": {}, "entity": {}},
|
|
),
|
|
)
|
|
def test_invalid_base_schema(schema):
|
|
"""Test base schema validation."""
|
|
with pytest.raises(vol.Invalid):
|
|
selector.validate_selector(schema)
|
|
|
|
|
|
def test_validate_selector():
|
|
"""Test return is the same as input."""
|
|
schema = {"device": {"manufacturer": "mock-manuf", "model": "mock-model"}}
|
|
assert schema == selector.validate_selector(schema)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"schema",
|
|
(
|
|
{},
|
|
{"integration": "zha"},
|
|
{"manufacturer": "mock-manuf"},
|
|
{"model": "mock-model"},
|
|
{"manufacturer": "mock-manuf", "model": "mock-model"},
|
|
{"integration": "zha", "manufacturer": "mock-manuf", "model": "mock-model"},
|
|
),
|
|
)
|
|
def test_device_selector_schema(schema):
|
|
"""Test device selector."""
|
|
selector.validate_selector({"device": schema})
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"schema",
|
|
(
|
|
{},
|
|
{"integration": "zha"},
|
|
{"domain": "light"},
|
|
{"integration": "zha", "domain": "light"},
|
|
),
|
|
)
|
|
def test_entity_selector_schema(schema):
|
|
"""Test entity selector."""
|
|
selector.validate_selector({"entity": schema})
|