Skip to content

Cleanup backup model after changes #47

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

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aiohasupervisor/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def upload_backup(
if options:
if options.location:
for location in options.location:
params.add("location", location or "")
params.add("location", location)
if options.filename:
params.add("filename", options.filename.as_posix())

Expand All @@ -145,7 +145,7 @@ async def download_backup(
"""Download backup and return stream."""
params = MultiDict()
if options and options.location:
params.add("location", options.location or "")
params.add("location", options.location)

result = await self._client.get(
f"backups/{backup}/download",
Expand Down
6 changes: 6 additions & 0 deletions aiohasupervisor/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
SupervisorRole,
)
from aiohasupervisor.models.backups import (
LOCATION_CLOUD_BACKUP,
LOCATION_LOCAL_STORAGE,
AddonSet,
Backup,
BackupAddon,
BackupComplete,
BackupContent,
BackupJob,
BackupLocationAttributes,
BackupsInfo,
BackupsOptions,
BackupType,
Expand Down Expand Up @@ -211,12 +214,15 @@
"GreenOptions",
"YellowInfo",
"YellowOptions",
"LOCATION_CLOUD_BACKUP",
"LOCATION_LOCAL_STORAGE",
"AddonSet",
"Backup",
"BackupAddon",
"BackupComplete",
"BackupContent",
"BackupJob",
"BackupLocationAttributes",
"BackupsInfo",
"BackupsOptions",
"BackupType",
Expand Down
20 changes: 9 additions & 11 deletions aiohasupervisor/models/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from enum import StrEnum
from pathlib import PurePath

from .base import DEFAULT, Options, Request, ResponseData
from .base import Options, Request, ResponseData

LOCATION_LOCAL_STORAGE = ".local"
LOCATION_CLOUD_BACKUP = ".cloud_backup"

# --- ENUMS ----

Expand Down Expand Up @@ -61,11 +64,6 @@ class BackupBaseFields(ABC):
name: str
date: datetime
type: BackupType
size: float
size_bytes: int
location: str | None
locations: set[str | None]
protected: bool
location_attributes: dict[str, BackupLocationAttributes]
compressed: bool

Expand Down Expand Up @@ -151,7 +149,7 @@ class FullBackupOptions(Request):
name: str | None = None
password: str | None = None
compressed: bool | None = None
location: str | list[str | None] | None = DEFAULT # type: ignore[assignment]
location: str | list[str] = None # type: ignore[assignment]
homeassistant_exclude_database: bool | None = None
background: bool | None = None
extra: dict | None = None
Expand Down Expand Up @@ -185,7 +183,7 @@ class FullRestoreOptions(Request):

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


@dataclass(frozen=True, slots=True)
Expand All @@ -197,7 +195,7 @@ class PartialRestoreOptions(FullRestoreOptions, PartialBackupRestoreOptions):
class UploadBackupOptions(Options):
"""UploadBackupOptions model."""

location: set[str | None] = None
location: set[str] = None
filename: PurePath | None = None


Expand All @@ -212,11 +210,11 @@ class UploadedBackup(ResponseData):
class RemoveBackupOptions(Request):
"""RemoveBackupOptions model."""

location: set[str | None] = None
location: set[str] = None


@dataclass(frozen=True, slots=True)
class DownloadBackupOptions(Request):
"""DownloadBackupOptions model."""

location: str | None = DEFAULT # type: ignore[assignment]
location: str = None # type: ignore[assignment]
49 changes: 18 additions & 31 deletions tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from aiohasupervisor import SupervisorClient
from aiohasupervisor.models import (
AddonSet,
BackupLocationAttributes,
BackupsOptions,
DownloadBackupOptions,
Folder,
Expand All @@ -24,7 +25,6 @@
RemoveBackupOptions,
UploadBackupOptions,
)
from aiohasupervisor.models.backups import BackupLocationAttributes

from . import load_fixture
from .const import SUPERVISOR_URL
Expand Down Expand Up @@ -143,23 +143,18 @@ async def test_backup_options_location() -> None:
"location": ["test", None]
}
assert FullBackupOptions(location="test").to_dict() == {"location": "test"}
assert FullBackupOptions(location=None).to_dict() == {"location": None}
assert FullBackupOptions().to_dict() == {}

assert PartialBackupOptions(
location=["test", None], folders={Folder.SSL}
location=["test", ".local"], folders={Folder.SSL}
).to_dict() == {
"location": ["test", None],
"location": ["test", ".local"],
"folders": ["ssl"],
}
assert PartialBackupOptions(location="test", folders={Folder.SSL}).to_dict() == {
"location": "test",
"folders": ["ssl"],
}
assert PartialBackupOptions(location=None, folders={Folder.SSL}).to_dict() == {
"location": None,
"folders": ["ssl"],
}
assert PartialBackupOptions(folders={Folder.SSL}).to_dict() == {"folders": ["ssl"]}


Expand All @@ -177,10 +172,11 @@ def backup_callback(url: str, **kwargs: dict[str, Any]) -> CallbackResult: # no
[
(FullBackupOptions(name="Test", background=True), None),
(FullBackupOptions(name="Test", background=False), "9ecf0028"),
(FullBackupOptions(name="Test", background=False, location=None), "9ecf0028"),
(FullBackupOptions(name="Test", background=False, location="test"), "9ecf0028"),
(
FullBackupOptions(name="Test", background=False, location={None, "test"}),
FullBackupOptions(
name="Test", background=False, location={".local", "test"}
),
"9ecf0028",
),
(
Expand Down Expand Up @@ -223,12 +219,6 @@ async def test_backups_full_backup(
PartialBackupOptions(name="Test", background=False, addons={"core_ssh"}),
"9ecf0028",
),
(
PartialBackupOptions(
name="Test", background=False, location=None, addons={"core_ssh"}
),
"9ecf0028",
),
(
PartialBackupOptions(
name="Test", background=False, location="test", addons={"core_ssh"}
Expand All @@ -239,7 +229,7 @@ async def test_backups_full_backup(
PartialBackupOptions(
name="Test",
background=False,
location={None, "test"},
location={".local", "test"},
addons={"core_ssh"},
),
"9ecf0028",
Expand Down Expand Up @@ -307,8 +297,6 @@ async def test_backup_info(
assert result.slug == "69558789"
assert result.type == "partial"
assert result.date == datetime(2024, 5, 31, 0, 0, 0, 0, UTC)
assert result.size == 0.01
assert result.size_bytes == 10123
assert result.compressed is True
assert result.addons[0].slug == "core_mosquitto"
assert result.addons[0].name == "Mosquitto broker"
Expand All @@ -324,8 +312,8 @@ async def test_backup_info(
assert result.folders == []
assert result.homeassistant_exclude_database is None
assert result.extra is None
assert result.location is None
assert result.locations == {None}
assert result.location_attributes[".local"].protected is False
assert result.location_attributes[".local"].size_bytes == 10123


async def test_backup_info_no_homeassistant(
Expand Down Expand Up @@ -370,8 +358,10 @@ async def test_backup_info_with_multiple_locations(
result = await supervisor_client.backups.backup_info("d13dedd0")
assert result.slug == "69558789"
assert result.type == "partial"
assert result.location is None
assert result.locations == {None, "Test"}
assert result.location_attributes[".local"].protected is False
assert result.location_attributes[".local"].size_bytes == 10123
assert result.location_attributes["Test"].protected is False
assert result.location_attributes["Test"].size_bytes == 10123


@pytest.mark.parametrize(
Expand All @@ -396,7 +386,6 @@ async def test_remove_backup(
None,
FullRestoreOptions(password="abc123"), # noqa: S106
FullRestoreOptions(background=True),
FullRestoreOptions(location=None),
FullRestoreOptions(location="test"),
],
)
Expand All @@ -419,7 +408,7 @@ async def test_full_restore(
"options",
[
PartialRestoreOptions(addons={"core_ssh"}),
PartialRestoreOptions(homeassistant=True, location=None),
PartialRestoreOptions(homeassistant=True, location=".local"),
PartialRestoreOptions(folders={Folder.SHARE, Folder.SSL}, location="test"),
PartialRestoreOptions(addons={"core_ssh"}, background=True),
PartialRestoreOptions(addons={"core_ssh"}, password="abc123"), # noqa: S106
Expand All @@ -444,7 +433,10 @@ async def test_partial_restore(
("options", "query"),
[
(None, ""),
(UploadBackupOptions(location={None, "test"}), "?location=&location=test"),
(
UploadBackupOptions(location={".local", "test"}),
"?location=.local&location=test",
),
(UploadBackupOptions(filename=PurePath("backup.tar")), "?filename=backup.tar"),
],
)
Expand Down Expand Up @@ -525,10 +517,6 @@ async def test_download_backup(
PartialBackupOptions(homeassistant=True, location="test"),
{"homeassistant": True, "location": "test"},
),
(
PartialBackupOptions(homeassistant=True, location=None),
{"homeassistant": True, "location": None},
),
(
PartialBackupOptions(homeassistant=True, filename=PurePath("backup.tar")),
{"homeassistant": True, "filename": "backup.tar"},
Expand Down Expand Up @@ -559,7 +547,6 @@ async def test_partial_backup_model(
{"location": [".cloud_backup", "test"]},
),
(FullBackupOptions(location="test"), {"location": "test"}),
(FullBackupOptions(location=None), {"location": None}),
(
FullBackupOptions(filename=PurePath("backup.tar")),
{"filename": "backup.tar"},
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy