mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 11:22:24 +01:00
Warn if underscore character is used in hostname (#2079)
* Prevent underscore character being used in 'name'. * Restrict underscores in hostnames, not all names. * Use hostname validator for node name. * Allow underscore in hostname but warn once. * Add renaming instructions link to warning. * Point underscore warning to FAQ section Co-authored-by: Otto Winter <otto@otto-winter.com> Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
@@ -40,6 +40,28 @@ def test_valid_name__invalid(value):
|
||||
config_validation.valid_name(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ("foo", "bar123", "foo-bar"))
|
||||
def test_hostname__valid(value):
|
||||
actual = config_validation.hostname(value)
|
||||
|
||||
assert actual == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ("foo bar", "foobar ", "foo#bar"))
|
||||
def test_hostname__invalid(value):
|
||||
with pytest.raises(Invalid):
|
||||
config_validation.hostname(value)
|
||||
|
||||
|
||||
def test_hostname__warning(caplog):
|
||||
actual = config_validation.hostname("foo_bar")
|
||||
assert actual == "foo_bar"
|
||||
assert (
|
||||
"Using the '_' (underscore) character in the hostname is discouraged"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@given(one_of(integers(), text()))
|
||||
def test_string__valid(value):
|
||||
actual = config_validation.string(value)
|
||||
|
Reference in New Issue
Block a user