mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Fix handling of renamed backup files in the core writer (#136898)
* Fix handling of renamed backup files in the core writer * Adjust mocking * Raise BackupAgentError instead of KeyError in get_backup_path * Add specific error indicating backup not found * Fix tests * Ensure backups are loaded * Fix tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Tests for the Backup integration."""
|
||||
|
||||
import asyncio
|
||||
from collections.abc import AsyncIterator, Iterable
|
||||
from collections.abc import AsyncIterator
|
||||
from io import BytesIO, StringIO
|
||||
import json
|
||||
import tarfile
|
||||
@@ -15,7 +15,12 @@ from homeassistant.components.backup import AddonInfo, AgentBackup, Folder
|
||||
from homeassistant.components.backup.const import DATA_MANAGER, DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import TEST_BACKUP_ABC123, BackupAgentTest, setup_backup_integration
|
||||
from .common import (
|
||||
TEST_BACKUP_ABC123,
|
||||
BackupAgentTest,
|
||||
aiter_from_iter,
|
||||
setup_backup_integration,
|
||||
)
|
||||
|
||||
from tests.common import MockUser, get_fixture_path
|
||||
from tests.typing import ClientSessionGenerator
|
||||
@@ -35,6 +40,9 @@ async def test_downloading_local_backup(
|
||||
"homeassistant.components.backup.backup.CoreLocalBackupAgent.async_get_backup",
|
||||
return_value=TEST_BACKUP_ABC123,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.backup.backup.CoreLocalBackupAgent.get_backup_path",
|
||||
),
|
||||
patch("pathlib.Path.exists", return_value=True),
|
||||
patch(
|
||||
"homeassistant.components.backup.http.FileResponse",
|
||||
@@ -73,9 +81,14 @@ async def test_downloading_local_encrypted_backup_file_not_found(
|
||||
await setup_backup_integration(hass)
|
||||
client = await hass_client()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.backup.backup.CoreLocalBackupAgent.async_get_backup",
|
||||
return_value=TEST_BACKUP_ABC123,
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.backup.backup.CoreLocalBackupAgent.async_get_backup",
|
||||
return_value=TEST_BACKUP_ABC123,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.backup.backup.CoreLocalBackupAgent.get_backup_path",
|
||||
),
|
||||
):
|
||||
resp = await client.get(
|
||||
"/api/backup/download/abc123?agent_id=backup.local&password=blah"
|
||||
@@ -93,12 +106,6 @@ async def test_downloading_local_encrypted_backup(
|
||||
await _test_downloading_encrypted_backup(hass_client, "backup.local")
|
||||
|
||||
|
||||
async def aiter_from_iter(iterable: Iterable) -> AsyncIterator:
|
||||
"""Convert an iterable to an async iterator."""
|
||||
for i in iterable:
|
||||
yield i
|
||||
|
||||
|
||||
@patch.object(BackupAgentTest, "async_download_backup")
|
||||
async def test_downloading_remote_encrypted_backup(
|
||||
download_mock,
|
||||
|
||||
Reference in New Issue
Block a user