mirror of
https://github.com/esphome/esphome.git
synced 2025-09-09 14:52:20 +01:00
[wizard] extend the wizard dashboard API to allow upload and empty config options (#10203)
This commit is contained in:
committed by
GitHub
parent
23c6650902
commit
c03d978b46
@@ -17,6 +17,7 @@ import esphome.wizard as wz
|
||||
@pytest.fixture
|
||||
def default_config():
|
||||
return {
|
||||
"type": "basic",
|
||||
"name": "test-name",
|
||||
"platform": "ESP8266",
|
||||
"board": "esp01_1m",
|
||||
@@ -125,6 +126,47 @@ def test_wizard_write_sets_platform(default_config, tmp_path, monkeypatch):
|
||||
assert "esp8266:" in generated_config
|
||||
|
||||
|
||||
def test_wizard_empty_config(tmp_path, monkeypatch):
|
||||
"""
|
||||
The wizard should be able to create an empty configuration
|
||||
"""
|
||||
# Given
|
||||
empty_config = {
|
||||
"type": "empty",
|
||||
"name": "test-empty",
|
||||
}
|
||||
monkeypatch.setattr(wz, "write_file", MagicMock())
|
||||
monkeypatch.setattr(CORE, "config_path", os.path.dirname(tmp_path))
|
||||
|
||||
# When
|
||||
wz.wizard_write(tmp_path, **empty_config)
|
||||
|
||||
# Then
|
||||
generated_config = wz.write_file.call_args.args[1]
|
||||
assert generated_config == ""
|
||||
|
||||
|
||||
def test_wizard_upload_config(tmp_path, monkeypatch):
|
||||
"""
|
||||
The wizard should be able to import an base64 encoded configuration
|
||||
"""
|
||||
# Given
|
||||
empty_config = {
|
||||
"type": "upload",
|
||||
"name": "test-upload",
|
||||
"file_text": "# imported file 📁\n\n",
|
||||
}
|
||||
monkeypatch.setattr(wz, "write_file", MagicMock())
|
||||
monkeypatch.setattr(CORE, "config_path", os.path.dirname(tmp_path))
|
||||
|
||||
# When
|
||||
wz.wizard_write(tmp_path, **empty_config)
|
||||
|
||||
# Then
|
||||
generated_config = wz.write_file.call_args.args[1]
|
||||
assert generated_config == "# imported file 📁\n\n"
|
||||
|
||||
|
||||
def test_wizard_write_defaults_platform_from_board_esp8266(
|
||||
default_config, tmp_path, monkeypatch
|
||||
):
|
||||
@@ -471,3 +513,22 @@ def test_wizard_requires_valid_ssid(tmpdir, monkeypatch, wizard_answers):
|
||||
|
||||
# Then
|
||||
assert retval == 0
|
||||
|
||||
|
||||
def test_wizard_write_protects_existing_config(tmpdir, default_config, monkeypatch):
|
||||
"""
|
||||
The wizard_write function should not overwrite existing config files and return False
|
||||
"""
|
||||
# Given
|
||||
config_file = tmpdir.join("test.yaml")
|
||||
original_content = "# Original config content\n"
|
||||
config_file.write(original_content)
|
||||
|
||||
monkeypatch.setattr(CORE, "config_path", str(tmpdir))
|
||||
|
||||
# When
|
||||
result = wz.wizard_write(str(config_file), **default_config)
|
||||
|
||||
# Then
|
||||
assert result is False # Should return False when file exists
|
||||
assert config_file.read() == original_content
|
||||
|
Reference in New Issue
Block a user