mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Adjust backup filename scheme (#137424)
* Adjust backup filename scheme * Update tests
This commit is contained in:
parent
ac42c9386c
commit
27b96160e2
@ -122,7 +122,7 @@ def read_backup(backup_path: Path) -> AgentBackup:
|
||||
def suggested_filename_from_name_date(name: str, date_str: str) -> str:
|
||||
"""Suggest a filename for the backup."""
|
||||
date = dt_util.parse_datetime(date_str, raise_on_error=True)
|
||||
return "_".join(f"{name} - {date.strftime('%Y-%m-%d %H.%M %S%f')}.tar".split())
|
||||
return "_".join(f"{name} {date.strftime('%Y-%m-%d %H.%M %S%f')}.tar".split())
|
||||
|
||||
|
||||
def suggested_filename(backup: AgentBackup) -> str:
|
||||
|
@ -103,9 +103,7 @@ async def test_upload(
|
||||
assert resp.status == 201
|
||||
assert open_mock.call_count == 1
|
||||
assert move_mock.call_count == 1
|
||||
assert (
|
||||
move_mock.mock_calls[0].args[1].name == "Test_-_1970-01-01_00.00_00000000.tar"
|
||||
)
|
||||
assert move_mock.mock_calls[0].args[1].name == "Test_1970-01-01_00.00_00000000.tar"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("read_backup")
|
||||
|
@ -426,7 +426,7 @@ async def test_create_backup_wrong_parameters(
|
||||
"backups",
|
||||
None,
|
||||
"Custom backup 2025.1.0",
|
||||
"Custom_backup_2025.1.0_-_2025-01-30_05.42_12345678.tar",
|
||||
"Custom_backup_2025.1.0_2025-01-30_05.42_12345678.tar",
|
||||
[LOCAL_AGENT_ID],
|
||||
[],
|
||||
0,
|
||||
@ -446,7 +446,7 @@ async def test_create_backup_wrong_parameters(
|
||||
"backups",
|
||||
None,
|
||||
"Custom backup 2025.1.0",
|
||||
"Custom_backup_2025.1.0_-_2025-01-30_05.42_12345678.tar",
|
||||
"Custom_backup_2025.1.0_2025-01-30_05.42_12345678.tar",
|
||||
[LOCAL_AGENT_ID, "test.remote"],
|
||||
[],
|
||||
0,
|
||||
@ -456,7 +456,7 @@ async def test_create_backup_wrong_parameters(
|
||||
"backups",
|
||||
"custom_name",
|
||||
"custom_name",
|
||||
"custom_name_-_2025-01-30_05.42_12345678.tar",
|
||||
"custom_name_2025-01-30_05.42_12345678.tar",
|
||||
[LOCAL_AGENT_ID],
|
||||
[],
|
||||
0,
|
||||
@ -476,7 +476,7 @@ async def test_create_backup_wrong_parameters(
|
||||
"backups",
|
||||
"custom_name",
|
||||
"custom_name",
|
||||
"custom_name_-_2025-01-30_05.42_12345678.tar",
|
||||
"custom_name_2025-01-30_05.42_12345678.tar",
|
||||
[LOCAL_AGENT_ID, "test.remote"],
|
||||
[],
|
||||
0,
|
||||
@ -487,7 +487,7 @@ async def test_create_backup_wrong_parameters(
|
||||
"backups",
|
||||
"custom_name",
|
||||
"custom_name",
|
||||
"custom_name_-_2025-01-30_05.42_12345678.tar",
|
||||
"custom_name_2025-01-30_05.42_12345678.tar",
|
||||
[LOCAL_AGENT_ID],
|
||||
["test.unavailable"],
|
||||
0,
|
||||
@ -1676,7 +1676,7 @@ async def test_exception_platform_post(hass: HomeAssistant) -> None:
|
||||
"agent_id=backup.local&agent_id=test.remote",
|
||||
2,
|
||||
1,
|
||||
["Test_-_1970-01-01_00.00_00000000.tar"],
|
||||
["Test_1970-01-01_00.00_00000000.tar"],
|
||||
{TEST_BACKUP_ABC123.backup_id: TEST_BACKUP_ABC123},
|
||||
b"test",
|
||||
0,
|
||||
@ -1685,7 +1685,7 @@ async def test_exception_platform_post(hass: HomeAssistant) -> None:
|
||||
"agent_id=backup.local",
|
||||
1,
|
||||
1,
|
||||
["Test_-_1970-01-01_00.00_00000000.tar"],
|
||||
["Test_1970-01-01_00.00_00000000.tar"],
|
||||
{},
|
||||
None,
|
||||
0,
|
||||
|
@ -529,10 +529,10 @@ async def test_encrypted_backup_streamer_error(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("name", "resulting_filename"),
|
||||
[
|
||||
("test", "test_-_2025-01-30_13.42_12345678.tar"),
|
||||
(" leading spaces", "leading_spaces_-_2025-01-30_13.42_12345678.tar"),
|
||||
("trailing spaces ", "trailing_spaces_-_2025-01-30_13.42_12345678.tar"),
|
||||
("double spaces ", "double_spaces_-_2025-01-30_13.42_12345678.tar"),
|
||||
("test", "test_2025-01-30_13.42_12345678.tar"),
|
||||
(" leading spaces", "leading_spaces_2025-01-30_13.42_12345678.tar"),
|
||||
("trailing spaces ", "trailing_spaces_2025-01-30_13.42_12345678.tar"),
|
||||
("double spaces ", "double_spaces_2025-01-30_13.42_12345678.tar"),
|
||||
],
|
||||
)
|
||||
def test_suggested_filename(name: str, resulting_filename: str) -> None:
|
||||
|
@ -140,7 +140,7 @@
|
||||
tuple(
|
||||
dict({
|
||||
'description': '{"addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", "date": "2025-01-01T01:23:45.678Z", "database_included": true, "extra_metadata": {"with_automatic_settings": false}, "folders": [], "homeassistant_included": true, "homeassistant_version": "2024.12.0", "name": "Test", "protected": false, "size": 987}',
|
||||
'name': 'Test_-_2025-01-01_01.23_45678000.tar',
|
||||
'name': 'Test_2025-01-01_01.23_45678000.tar',
|
||||
'parents': list([
|
||||
'HA folder ID',
|
||||
]),
|
||||
@ -211,7 +211,7 @@
|
||||
tuple(
|
||||
dict({
|
||||
'description': '{"addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", "date": "2025-01-01T01:23:45.678Z", "database_included": true, "extra_metadata": {"with_automatic_settings": false}, "folders": [], "homeassistant_included": true, "homeassistant_version": "2024.12.0", "name": "Test", "protected": false, "size": 987}',
|
||||
'name': 'Test_-_2025-01-01_01.23_45678000.tar',
|
||||
'name': 'Test_2025-01-01_01.23_45678000.tar',
|
||||
'parents': list([
|
||||
'new folder id',
|
||||
]),
|
||||
|
@ -887,7 +887,7 @@ DEFAULT_BACKUP_OPTIONS = supervisor_backups.PartialBackupOptions(
|
||||
"supervisor.backup_request_date": "2025-01-30T05:42:12.345678-08:00",
|
||||
"with_automatic_settings": False,
|
||||
},
|
||||
filename=PurePath("Test_-_2025-01-30_05.42_12345678.tar"),
|
||||
filename=PurePath("Test_2025-01-30_05.42_12345678.tar"),
|
||||
folders={"ssl"},
|
||||
homeassistant_exclude_database=False,
|
||||
homeassistant=True,
|
||||
@ -1400,7 +1400,7 @@ async def test_reader_writer_create_per_agent_encryption(
|
||||
upload_locations
|
||||
)
|
||||
for call in supervisor_client.backups.upload_backup.mock_calls:
|
||||
assert call.args[1].filename == PurePath("Test_-_2025-01-30_05.42_12345678.tar")
|
||||
assert call.args[1].filename == PurePath("Test_2025-01-30_05.42_12345678.tar")
|
||||
upload_call_locations: set = call.args[1].location
|
||||
assert len(upload_call_locations) == 1
|
||||
assert upload_call_locations.pop() in upload_locations
|
||||
|
@ -36,7 +36,7 @@ from .consts import HOST, MACS, PASSWORD, PORT, SERIAL, USE_SSL, USERNAME
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||
|
||||
BASE_FILENAME = "Automatic_backup_2025.2.0.dev0_-_2025-01-09_20.14_35457323"
|
||||
BASE_FILENAME = "Automatic_backup_2025.2.0.dev0_2025-01-09_20.14_35457323"
|
||||
|
||||
|
||||
class MockStreamReaderChunked(MockStreamReader):
|
||||
@ -525,7 +525,7 @@ async def test_agents_upload(
|
||||
protected=True,
|
||||
size=0,
|
||||
)
|
||||
base_filename = "Test_-_1970-01-01_00.00_00000000"
|
||||
base_filename = "Test_1970-01-01_00.00_00000000"
|
||||
|
||||
with (
|
||||
patch(
|
||||
@ -576,7 +576,7 @@ async def test_agents_upload_error(
|
||||
protected=True,
|
||||
size=0,
|
||||
)
|
||||
base_filename = "Test_-_1970-01-01_00.00_00000000"
|
||||
base_filename = "Test_1970-01-01_00.00_00000000"
|
||||
|
||||
# fail to upload the tar file
|
||||
with (
|
||||
|
Loading…
x
Reference in New Issue
Block a user