mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 18:18:21 +00:00
improve backup filenames
This commit is contained in:
parent
0895ac6a82
commit
40fa4721ed
@ -122,7 +122,7 @@ def read_backup(backup_path: Path) -> AgentBackup:
|
|||||||
def suggested_filename_from_name_date(name: str, date_str: str) -> str:
|
def suggested_filename_from_name_date(name: str, date_str: str) -> str:
|
||||||
"""Suggest a filename for the backup."""
|
"""Suggest a filename for the backup."""
|
||||||
date = dt_util.parse_datetime(date_str, raise_on_error=True)
|
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')}.tar".split())
|
||||||
|
|
||||||
|
|
||||||
def suggested_filename(backup: AgentBackup) -> str:
|
def suggested_filename(backup: AgentBackup) -> str:
|
||||||
|
@ -103,9 +103,7 @@ async def test_upload(
|
|||||||
assert resp.status == 201
|
assert resp.status == 201
|
||||||
assert open_mock.call_count == 1
|
assert open_mock.call_count == 1
|
||||||
assert move_mock.call_count == 1
|
assert move_mock.call_count == 1
|
||||||
assert (
|
assert move_mock.mock_calls[0].args[1].name == "Test-1970-01-01_00-00-00.tar"
|
||||||
move_mock.mock_calls[0].args[1].name == "Test_-_1970-01-01_00.00_00000000.tar"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("read_backup")
|
@pytest.mark.usefixtures("read_backup")
|
||||||
|
@ -418,7 +418,7 @@ async def test_create_backup_wrong_parameters(
|
|||||||
"backups",
|
"backups",
|
||||||
None,
|
None,
|
||||||
"Custom backup 2025.1.0",
|
"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-12.tar",
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -434,7 +434,7 @@ async def test_create_backup_wrong_parameters(
|
|||||||
"backups",
|
"backups",
|
||||||
None,
|
None,
|
||||||
"Custom backup 2025.1.0",
|
"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-12.tar",
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -442,7 +442,7 @@ async def test_create_backup_wrong_parameters(
|
|||||||
"backups",
|
"backups",
|
||||||
"custom_name",
|
"custom_name",
|
||||||
"custom_name",
|
"custom_name",
|
||||||
"custom_name_-_2025-01-30_05.42_12345678.tar",
|
"custom_name-2025-01-30_05-42-12.tar",
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -458,7 +458,7 @@ async def test_create_backup_wrong_parameters(
|
|||||||
"backups",
|
"backups",
|
||||||
"custom_name",
|
"custom_name",
|
||||||
"custom_name",
|
"custom_name",
|
||||||
"custom_name_-_2025-01-30_05.42_12345678.tar",
|
"custom_name-2025-01-30_05-42-12.tar",
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -1611,7 +1611,7 @@ async def test_exception_platform_post(hass: HomeAssistant) -> None:
|
|||||||
"agent_id=backup.local&agent_id=test.remote",
|
"agent_id=backup.local&agent_id=test.remote",
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
["Test_-_1970-01-01_00.00_00000000.tar"],
|
["Test-1970-01-01_00-00-00.tar"],
|
||||||
{TEST_BACKUP_ABC123.backup_id: TEST_BACKUP_ABC123},
|
{TEST_BACKUP_ABC123.backup_id: TEST_BACKUP_ABC123},
|
||||||
b"test",
|
b"test",
|
||||||
0,
|
0,
|
||||||
@ -1620,7 +1620,7 @@ async def test_exception_platform_post(hass: HomeAssistant) -> None:
|
|||||||
"agent_id=backup.local",
|
"agent_id=backup.local",
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
["Test_-_1970-01-01_00.00_00000000.tar"],
|
["Test-1970-01-01_00-00-00.tar"],
|
||||||
{},
|
{},
|
||||||
None,
|
None,
|
||||||
0,
|
0,
|
||||||
|
@ -529,10 +529,10 @@ async def test_encrypted_backup_streamer_error(hass: HomeAssistant) -> None:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("name", "resulting_filename"),
|
("name", "resulting_filename"),
|
||||||
[
|
[
|
||||||
("test", "test_-_2025-01-30_13.42_12345678.tar"),
|
("test", "test-2025-01-30_13-42-12.tar"),
|
||||||
(" leading spaces", "leading_spaces_-_2025-01-30_13.42_12345678.tar"),
|
(" leading spaces", "leading_spaces-2025-01-30_13-42-12.tar"),
|
||||||
("trailing spaces ", "trailing_spaces_-_2025-01-30_13.42_12345678.tar"),
|
("trailing spaces ", "trailing_spaces_-2025-01-30_13-42-12.tar"),
|
||||||
("double spaces ", "double_spaces_-_2025-01-30_13.42_12345678.tar"),
|
("double spaces ", "double_spaces_-2025-01-30_13-42-12.tar"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_suggested_filename(name: str, resulting_filename: str) -> None:
|
def test_suggested_filename(name: str, resulting_filename: str) -> None:
|
||||||
|
@ -140,7 +140,7 @@
|
|||||||
tuple(
|
tuple(
|
||||||
dict({
|
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}',
|
'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-45.tar',
|
||||||
'parents': list([
|
'parents': list([
|
||||||
'HA folder ID',
|
'HA folder ID',
|
||||||
]),
|
]),
|
||||||
@ -211,7 +211,7 @@
|
|||||||
tuple(
|
tuple(
|
||||||
dict({
|
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}',
|
'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-45.tar',
|
||||||
'parents': list([
|
'parents': list([
|
||||||
'new folder id',
|
'new folder id',
|
||||||
]),
|
]),
|
||||||
|
@ -880,7 +880,7 @@ DEFAULT_BACKUP_OPTIONS = supervisor_backups.PartialBackupOptions(
|
|||||||
"supervisor.backup_request_date": "2025-01-30T05:42:12.345678-08:00",
|
"supervisor.backup_request_date": "2025-01-30T05:42:12.345678-08:00",
|
||||||
"with_automatic_settings": False,
|
"with_automatic_settings": False,
|
||||||
},
|
},
|
||||||
filename=PurePath("Test_-_2025-01-30_05.42_12345678.tar"),
|
filename=PurePath("Test-2025-01-30_05-42-12.tar"),
|
||||||
folders={"ssl"},
|
folders={"ssl"},
|
||||||
homeassistant_exclude_database=False,
|
homeassistant_exclude_database=False,
|
||||||
homeassistant=True,
|
homeassistant=True,
|
||||||
@ -1393,7 +1393,7 @@ async def test_reader_writer_create_per_agent_encryption(
|
|||||||
upload_locations
|
upload_locations
|
||||||
)
|
)
|
||||||
for call in supervisor_client.backups.upload_backup.mock_calls:
|
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-12.tar")
|
||||||
upload_call_locations: set = call.args[1].location
|
upload_call_locations: set = call.args[1].location
|
||||||
assert len(upload_call_locations) == 1
|
assert len(upload_call_locations) == 1
|
||||||
assert upload_call_locations.pop() in upload_locations
|
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.common import MockConfigEntry
|
||||||
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
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-35"
|
||||||
|
|
||||||
|
|
||||||
class MockStreamReaderChunked(MockStreamReader):
|
class MockStreamReaderChunked(MockStreamReader):
|
||||||
@ -525,7 +525,7 @@ async def test_agents_upload(
|
|||||||
protected=True,
|
protected=True,
|
||||||
size=0,
|
size=0,
|
||||||
)
|
)
|
||||||
base_filename = "Test_-_1970-01-01_00.00_00000000"
|
base_filename = "Test-1970-01-01_00-00-00"
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
@ -576,7 +576,7 @@ async def test_agents_upload_error(
|
|||||||
protected=True,
|
protected=True,
|
||||||
size=0,
|
size=0,
|
||||||
)
|
)
|
||||||
base_filename = "Test_-_1970-01-01_00.00_00000000"
|
base_filename = "Test-1970-01-01_00-00-00"
|
||||||
|
|
||||||
# fail to upload the tar file
|
# fail to upload the tar file
|
||||||
with (
|
with (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user