Skip to content

Commit 34acdc9

Browse files
committed
Add tests of options
1 parent 08581a9 commit 34acdc9

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

aiohasupervisor/models/__init__.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323
StoreInfo,
2424
SupervisorRole,
2525
)
26+
from aiohasupervisor.models.backups import (
27+
Backup,
28+
BackupAddon,
29+
BackupComplete,
30+
BackupContent,
31+
BackupJob,
32+
BackupsInfo,
33+
BackupsOptions,
34+
BackupType,
35+
Folder,
36+
FreezeOptions,
37+
FullBackupOptions,
38+
FullRestoreOptions,
39+
NewBackup,
40+
PartialBackupOptions,
41+
PartialRestoreOptions,
42+
)
2643
from aiohasupervisor.models.homeassistant import (
2744
HomeAssistantInfo,
2845
HomeAssistantOptions,
@@ -46,22 +63,6 @@
4663
YellowInfo,
4764
YellowOptions,
4865
)
49-
from aiohasupervisor.models.backups import (
50-
Backup,
51-
BackupAddon,
52-
BackupComplete,
53-
BackupContent,
54-
BackupJob,
55-
BackupsInfo,
56-
BackupsOptions,
57-
BackupType,
58-
Folder,
59-
FullBackupOptions,
60-
FullRestoreOptions,
61-
NewBackup,
62-
PartialBackupOptions,
63-
PartialRestoreOptions,
64-
)
6566
from aiohasupervisor.models.resolution import (
6667
Check,
6768
CheckOptions,
@@ -163,6 +164,7 @@
163164
"BackupsOptions",
164165
"BackupType",
165166
"Folder",
167+
"FreezeOptions",
166168
"FullBackupOptions",
167169
"FullRestoreOptions",
168170
"NewBackup",

tests/test_backups.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from aiohasupervisor.models import (
1212
BackupsOptions,
1313
Folder,
14+
FreezeOptions,
1415
FullBackupOptions,
1516
PartialBackupOptions,
1617
PartialRestoreOptions,
@@ -78,12 +79,15 @@ async def test_backups_reload(
7879
}
7980

8081

82+
@pytest.mark.parametrize("options", [None, FreezeOptions(timeout=1000)])
8183
async def test_backups_freeze(
82-
responses: aioresponses, supervisor_client: SupervisorClient
84+
responses: aioresponses,
85+
supervisor_client: SupervisorClient,
86+
options: FreezeOptions | None,
8387
) -> None:
8488
"""Test backups freeze API."""
8589
responses.post(f"{SUPERVISOR_URL}/backups/freeze", status=200)
86-
assert await supervisor_client.backups.freeze() is None
90+
assert await supervisor_client.backups.freeze(options) is None
8791
assert responses.requests.keys() == {
8892
("POST", URL(f"{SUPERVISOR_URL}/backups/freeze"))
8993
}
@@ -120,31 +124,33 @@ async def test_partial_restore_options() -> None:
120124

121125
def backup_callback(url: str, **kwargs: dict[str, Any]) -> CallbackResult: # noqa: ARG001
122126
"""Return response based on whether backup was in background or not."""
123-
if kwargs["json"]["background"]:
127+
if kwargs["json"] and kwargs["json"]["background"]:
124128
fixture = "backup_background.json"
125129
else:
126130
fixture = "backup_foreground.json"
127131
return CallbackResult(status=200, body=load_fixture(fixture))
128132

129133

130134
@pytest.mark.parametrize(
131-
("background", "slug"),
132-
[(True, None), (False, "9ecf0028")],
135+
("options", "slug"),
136+
[
137+
(FullBackupOptions(name="Test", background=True), None),
138+
(FullBackupOptions(name="Test", background=False), "9ecf0028"),
139+
(None, "9ecf0028"),
140+
],
133141
)
134142
async def test_backups_full_backup(
135143
responses: aioresponses,
136144
supervisor_client: SupervisorClient,
137-
background: bool, # noqa: FBT001
145+
options: FullBackupOptions | None,
138146
slug: str | None,
139147
) -> None:
140148
"""Test backups full backup API."""
141149
responses.post(
142150
f"{SUPERVISOR_URL}/backups/new/full",
143151
callback=backup_callback,
144152
)
145-
result = await supervisor_client.backups.full_backup(
146-
FullBackupOptions(name="test", background=background)
147-
)
153+
result = await supervisor_client.backups.full_backup(options)
148154
assert result.job_id == "dc9dbc16f6ad4de592ffa72c807ca2bf"
149155
assert result.slug == slug
150156

0 commit comments

Comments
 (0)