1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-16 18:22:22 +01:00
This commit is contained in:
J. Nick Koston
2025-09-15 17:23:01 -05:00
parent fa00e07e10
commit 47d24edd0e

View File

@@ -599,18 +599,14 @@ async def test_archive_request_handler_post(
test_config = config_dir / "test_archive.yaml" test_config = config_dir / "test_archive.yaml"
test_config.write_text("esphome:\n name: test_archive\n") test_config.write_text("esphome:\n name: test_archive\n")
# Mock storage_json to return None (no storage) # Archive the configuration
with patch("esphome.dashboard.web_server.StorageJSON.load") as mock_load: response = await dashboard.fetch(
mock_load.return_value = None "/archive",
method="POST",
# Archive the configuration body="configuration=test_archive.yaml",
response = await dashboard.fetch( headers={"Content-Type": "application/x-www-form-urlencoded"},
"/archive", )
method="POST", assert response.code == 200
body="configuration=test_archive.yaml",
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
assert response.code == 200
# Verify file was moved to archive # Verify file was moved to archive
assert not test_config.exists() assert not test_config.exists()
@@ -626,6 +622,7 @@ async def test_archive_handler_with_build_folder(
mock_archive_storage_path: MagicMock, mock_archive_storage_path: MagicMock,
mock_ext_storage_path: MagicMock, mock_ext_storage_path: MagicMock,
mock_dashboard_settings: MagicMock, mock_dashboard_settings: MagicMock,
mock_storage_json: MagicMock,
tmp_path: Path, tmp_path: Path,
) -> None: ) -> None:
"""Test ArchiveRequestHandler.post with storage_json and build folder.""" """Test ArchiveRequestHandler.post with storage_json and build folder."""
@@ -654,20 +651,19 @@ async def test_archive_handler_with_build_folder(
mock_archive_storage_path.return_value = str(archive_dir) mock_archive_storage_path.return_value = str(archive_dir)
# Mock storage_json with device name and build_path # Mock storage_json with device name and build_path
with patch("esphome.dashboard.web_server.StorageJSON.load") as mock_load: mock_storage = MagicMock()
mock_storage = MagicMock() mock_storage.name = "test_device"
mock_storage.name = "test_device" mock_storage.build_path = str(build_folder)
mock_storage.build_path = str(build_folder) mock_storage_json.load.return_value = mock_storage
mock_load.return_value = mock_storage
# Archive the configuration # Archive the configuration
response = await dashboard.fetch( response = await dashboard.fetch(
"/archive", "/archive",
method="POST", method="POST",
body=f"configuration={configuration}", body=f"configuration={configuration}",
headers={"Content-Type": "application/x-www-form-urlencoded"}, headers={"Content-Type": "application/x-www-form-urlencoded"},
) )
assert response.code == 200 assert response.code == 200
# Verify config file was moved to archive # Verify config file was moved to archive
assert not test_config.exists() assert not test_config.exists()
@@ -685,6 +681,7 @@ async def test_archive_handler_no_build_folder(
mock_archive_storage_path: MagicMock, mock_archive_storage_path: MagicMock,
mock_ext_storage_path: MagicMock, mock_ext_storage_path: MagicMock,
mock_dashboard_settings: MagicMock, mock_dashboard_settings: MagicMock,
mock_storage_json: MagicMock,
tmp_path: Path, tmp_path: Path,
) -> None: ) -> None:
"""Test ArchiveRequestHandler.post with storage_json but no build folder.""" """Test ArchiveRequestHandler.post with storage_json but no build folder."""
@@ -707,20 +704,19 @@ async def test_archive_handler_no_build_folder(
mock_archive_storage_path.return_value = str(archive_dir) mock_archive_storage_path.return_value = str(archive_dir)
# Mock storage_json with device name but no build_path # Mock storage_json with device name but no build_path
with patch("esphome.dashboard.web_server.StorageJSON.load") as mock_load: mock_storage = MagicMock()
mock_storage = MagicMock() mock_storage.name = "test_device"
mock_storage.name = "test_device" mock_storage.build_path = None
mock_storage.build_path = None mock_storage_json.load.return_value = mock_storage
mock_load.return_value = mock_storage
# Archive the configuration (should not fail even without build folder) # Archive the configuration (should not fail even without build folder)
response = await dashboard.fetch( response = await dashboard.fetch(
"/archive", "/archive",
method="POST", method="POST",
body=f"configuration={configuration}", body=f"configuration={configuration}",
headers={"Content-Type": "application/x-www-form-urlencoded"}, headers={"Content-Type": "application/x-www-form-urlencoded"},
) )
assert response.code == 200 assert response.code == 200
# Verify config file was moved to archive # Verify config file was moved to archive
assert not test_config.exists() assert not test_config.exists()