-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reading extra metadata for local backups (#133643)
- Loading branch information
1 parent
5834ecb
commit 4c96b83
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""Tests for the Backup integration's utility functions.""" | ||
|
||
from __future__ import annotations | ||
|
||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
||
from homeassistant.components.backup import AddonInfo, AgentBackup, Folder | ||
from homeassistant.components.backup.util import read_backup | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("backup_json_content", "expected_backup"), | ||
[ | ||
( | ||
b'{"compressed":true,"date":"2024-12-02T07:23:58.261875-05:00","homeassistant":' | ||
b'{"exclude_database":true,"version":"2024.12.0.dev0"},"name":"test",' | ||
b'"protected":true,"slug":"455645fe","type":"partial","version":2}', | ||
AgentBackup( | ||
addons=[], | ||
backup_id="455645fe", | ||
date="2024-12-02T07:23:58.261875-05:00", | ||
database_included=False, | ||
extra_metadata={}, | ||
folders=[], | ||
homeassistant_included=True, | ||
homeassistant_version="2024.12.0.dev0", | ||
name="test", | ||
protected=True, | ||
size=1234, | ||
), | ||
), | ||
( | ||
b'{"slug":"d4b8fdc6","version":2,"name":"Core 2025.1.0.dev0",' | ||
b'"date":"2024-12-20T11:27:51.119062+00:00","type":"partial",' | ||
b'"supervisor_version":"2024.12.1.dev1803",' | ||
b'"extra":{"instance_id":"6b453733d2d74d2a9ae432ff2fbaaa64",' | ||
b'"with_automatic_settings":false},"homeassistant":' | ||
b'{"version":"2025.1.0.dev202412200230","exclude_database":false,"size":0.0},' | ||
b'"compressed":true,"protected":true,"repositories":[' | ||
b'"https://github.com/home-assistant/hassio-addons-development","local",' | ||
b'"https://github.com/esphome/home-assistant-addon","core",' | ||
b'"https://github.com/music-assistant/home-assistant-addon",' | ||
b'"https://github.com/hassio-addons/repository"],"crypto":"aes128",' | ||
b'"folders":["share","media"],"addons":[{"slug":"core_configurator",' | ||
b'"name":"File editor","version":"5.5.0","size":0.0},' | ||
b'{"slug":"ae6e943c_remote_api","name":"Remote API proxy",' | ||
b'"version":"1.3.0","size":0.0}],"docker":{"registries":{}}}', | ||
AgentBackup( | ||
addons=[ | ||
AddonInfo( | ||
name="File editor", | ||
slug="core_configurator", | ||
version="5.5.0", | ||
), | ||
AddonInfo( | ||
name="Remote API proxy", | ||
slug="ae6e943c_remote_api", | ||
version="1.3.0", | ||
), | ||
], | ||
backup_id="d4b8fdc6", | ||
date="2024-12-20T11:27:51.119062+00:00", | ||
database_included=True, | ||
extra_metadata={ | ||
"instance_id": "6b453733d2d74d2a9ae432ff2fbaaa64", | ||
"with_automatic_settings": False, | ||
}, | ||
folders=[Folder.SHARE, Folder.MEDIA], | ||
homeassistant_included=True, | ||
homeassistant_version="2025.1.0.dev202412200230", | ||
name="Core 2025.1.0.dev0", | ||
protected=True, | ||
size=1234, | ||
), | ||
), | ||
], | ||
) | ||
def test_read_backup(backup_json_content: bytes, expected_backup: AgentBackup) -> None: | ||
"""Test reading a backup.""" | ||
mock_path = Mock() | ||
mock_path.stat.return_value.st_size = 1234 | ||
|
||
with patch("homeassistant.components.backup.util.tarfile.open") as mock_open_tar: | ||
mock_open_tar.return_value.__enter__.return_value.extractfile().read.return_value = backup_json_content | ||
backup = read_backup(mock_path) | ||
assert backup == expected_backup |