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:
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncIterator, Callable, Coroutine
|
||||
from collections.abc import AsyncIterator, Callable, Coroutine, Iterable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import ANY, AsyncMock, Mock, patch
|
||||
@@ -52,10 +52,17 @@ TEST_BACKUP_DEF456 = AgentBackup(
|
||||
protected=False,
|
||||
size=1,
|
||||
)
|
||||
TEST_BACKUP_PATH_DEF456 = Path("custom_def456.tar")
|
||||
|
||||
TEST_DOMAIN = "test"
|
||||
|
||||
|
||||
async def aiter_from_iter(iterable: Iterable) -> AsyncIterator:
|
||||
"""Convert an iterable to an async iterator."""
|
||||
for i in iterable:
|
||||
yield i
|
||||
|
||||
|
||||
class BackupAgentTest(BackupAgent):
|
||||
"""Test backup agent."""
|
||||
|
||||
@@ -162,7 +169,13 @@ async def setup_backup_integration(
|
||||
if with_hassio and agent_id == LOCAL_AGENT_ID:
|
||||
continue
|
||||
agent = hass.data[DATA_MANAGER].backup_agents[agent_id]
|
||||
agent._backups = {backups.backup_id: backups for backups in agent_backups}
|
||||
|
||||
async def open_stream() -> AsyncIterator[bytes]:
|
||||
"""Open a stream."""
|
||||
return aiter_from_iter((b"backup data",))
|
||||
|
||||
for backup in agent_backups:
|
||||
await agent.async_upload_backup(open_stream=open_stream, backup=backup)
|
||||
if agent_id == LOCAL_AGENT_ID:
|
||||
agent._loaded_backups = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user