Skip to content

Commit

Permalink
Add restore from location option (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 authored Dec 17, 2024
1 parent b918d50 commit 217184d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions aiohasupervisor/models/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class FullRestoreOptions(Request):

password: str | None = None
background: bool | None = None
location: str | None = DEFAULT # type: ignore[assignment]


@dataclass(frozen=True, slots=True)
Expand Down
35 changes: 29 additions & 6 deletions tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Folder,
FreezeOptions,
FullBackupOptions,
FullRestoreOptions,
PartialBackupOptions,
PartialRestoreOptions,
RemoveBackupOptions,
Expand Down Expand Up @@ -372,31 +373,53 @@ async def test_remove_backup(
}


@pytest.mark.parametrize(
"options",
[
None,
FullRestoreOptions(password="abc123"), # noqa: S106
FullRestoreOptions(background=True),
FullRestoreOptions(location=None),
FullRestoreOptions(location="test"),
],
)
async def test_full_restore(
responses: aioresponses, supervisor_client: SupervisorClient
responses: aioresponses,
supervisor_client: SupervisorClient,
options: FullRestoreOptions | None,
) -> None:
"""Test full restore API."""
responses.post(
f"{SUPERVISOR_URL}/backups/abc123/restore/full",
status=200,
body=load_fixture("backup_restore.json"),
)
result = await supervisor_client.backups.full_restore("abc123")
result = await supervisor_client.backups.full_restore("abc123", options)
assert result.job_id == "dc9dbc16f6ad4de592ffa72c807ca2bf"


@pytest.mark.parametrize(
"options",
[
PartialRestoreOptions(addons={"core_ssh"}),
PartialRestoreOptions(homeassistant=True, location=None),
PartialRestoreOptions(folders={Folder.SHARE, Folder.SSL}, location="test"),
PartialRestoreOptions(addons={"core_ssh"}, background=True),
PartialRestoreOptions(addons={"core_ssh"}, password="abc123"), # noqa: S106
],
)
async def test_partial_restore(
responses: aioresponses, supervisor_client: SupervisorClient
responses: aioresponses,
supervisor_client: SupervisorClient,
options: PartialRestoreOptions,
) -> None:
"""Test partial restore API."""
responses.post(
f"{SUPERVISOR_URL}/backups/abc123/restore/partial",
status=200,
body=load_fixture("backup_restore.json"),
)
result = await supervisor_client.backups.partial_restore(
"abc123", PartialRestoreOptions(addons={"core_ssh"})
)
result = await supervisor_client.backups.partial_restore("abc123", options)
assert result.job_id == "dc9dbc16f6ad4de592ffa72c807ca2bf"


Expand Down

0 comments on commit 217184d

Please sign in to comment.