Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle backup delete after config #131259

Merged
merged 15 commits into from
Nov 23, 2024
Prev Previous commit
Next Next commit
Test more delete after days
  • Loading branch information
MartinHjelmare committed Nov 22, 2024
commit c2cb9db6126819af59802ae5ab665fd2f81b85f3
92 changes: 90 additions & 2 deletions tests/components/backup/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ async def test_config_delete_after_copies_logic(
"last_backup_time",
"start_time",
"next_time",
"get_backups_calls",
"delete_calls",
"delete_args_list",
),
Expand All @@ -1306,16 +1307,101 @@ async def test_config_delete_after_copies_logic(
{
"type": "backup/config/update",
"create_backup": {"agent_ids": ["test-agent"]},
"delete_after": {"copies": None, "days": 1},
"delete_after": {"copies": None, "days": 2},
"schedule": "never",
},
{"backup-1": MagicMock(date="2024-11-11T04:45:00+01:00")},
{
"backup-1": MagicMock(date="2024-11-10T04:45:00+01:00"),
"backup-2": MagicMock(date="2024-11-11T04:45:00+01:00"),
},
{},
{},
"2024-11-11T04:45:00+01:00",
"2024-11-11T12:00:00+01:00",
"2024-11-12T12:00:00+01:00",
1,
1,
[call("backup-1")],
),
(
{
"type": "backup/config/update",
"create_backup": {"agent_ids": ["test-agent"]},
"delete_after": {"copies": None, "days": 3},
"schedule": "never",
},
{
"backup-1": MagicMock(date="2024-11-10T04:45:00+01:00"),
"backup-2": MagicMock(date="2024-11-11T04:45:00+01:00"),
},
{},
{},
"2024-11-11T04:45:00+01:00",
"2024-11-11T12:00:00+01:00",
"2024-11-12T12:00:00+01:00",
1,
0,
[],
),
(
{
"type": "backup/config/update",
"create_backup": {"agent_ids": ["test-agent"]},
"delete_after": {"copies": None, "days": 2},
"schedule": "never",
},
{
"backup-1": MagicMock(date="2024-11-09T04:45:00+01:00"),
"backup-2": MagicMock(date="2024-11-10T04:45:00+01:00"),
"backup-3": MagicMock(date="2024-11-11T04:45:00+01:00"),
},
{},
{},
"2024-11-11T04:45:00+01:00",
"2024-11-11T12:00:00+01:00",
"2024-11-12T12:00:00+01:00",
1,
2,
[call("backup-1"), call("backup-2")],
),
(
{
"type": "backup/config/update",
"create_backup": {"agent_ids": ["test-agent"]},
"delete_after": {"copies": None, "days": 2},
"schedule": "never",
},
{
"backup-1": MagicMock(date="2024-11-10T04:45:00+01:00"),
"backup-2": MagicMock(date="2024-11-11T04:45:00+01:00"),
},
{"test-agent": BackupAgentError("Boom!")},
{},
"2024-11-11T04:45:00+01:00",
"2024-11-11T12:00:00+01:00",
"2024-11-12T12:00:00+01:00",
1,
0,
[],
),
(
{
"type": "backup/config/update",
"create_backup": {"agent_ids": ["test-agent"]},
"delete_after": {"copies": None, "days": 2},
"schedule": "never",
},
{
"backup-1": MagicMock(date="2024-11-10T04:45:00+01:00"),
"backup-2": MagicMock(date="2024-11-11T04:45:00+01:00"),
},
{},
{"test-agent": BackupAgentError("Boom!")},
"2024-11-11T04:45:00+01:00",
"2024-11-11T12:00:00+01:00",
"2024-11-12T12:00:00+01:00",
1,
1,
[call("backup-1")],
),
],
Expand All @@ -1334,6 +1420,7 @@ async def test_config_delete_after_days_logic(
last_backup_time: str,
start_time: str,
next_time: str,
get_backups_calls: int,
delete_calls: int,
delete_args_list: list[Any],
) -> None:
Expand Down Expand Up @@ -1374,6 +1461,7 @@ async def test_config_delete_after_days_logic(
freezer.move_to(next_time)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert get_backups.call_count == get_backups_calls
assert delete_backup.call_count == delete_calls
assert delete_backup.call_args_list == delete_args_list
async_fire_time_changed(hass, fire_all=True) # flush out storage save
Expand Down