@@ -133,7 +133,7 @@ async def test_partial_restore_options() -> None:
133133
134134def backup_callback (url : str , ** kwargs : dict [str , Any ]) -> CallbackResult : # noqa: ARG001
135135 """Return response based on whether backup was in background or not."""
136- if kwargs ["json" ] and kwargs ["json" ][ "background" ] :
136+ if kwargs ["json" ] and kwargs ["json" ]. get ( "background" ) :
137137 fixture = "backup_background.json"
138138 else :
139139 fixture = "backup_foreground.json"
@@ -145,6 +145,19 @@ def backup_callback(url: str, **kwargs: dict[str, Any]) -> CallbackResult: # no
145145 [
146146 (FullBackupOptions (name = "Test" , background = True ), None ),
147147 (FullBackupOptions (name = "Test" , background = False ), "9ecf0028" ),
148+ (FullBackupOptions (name = "Test" , background = False , location = None ), "9ecf0028" ),
149+ (FullBackupOptions (name = "Test" , background = False , location = "test" ), "9ecf0028" ),
150+ (
151+ FullBackupOptions (name = "Test" , background = False , location = {None , "test" }),
152+ "9ecf0028" ,
153+ ),
154+ (
155+ FullBackupOptions (
156+ name = "Test" , background = False , extra = {"user" : "test" , "scheduled" : True }
157+ ),
158+ "9ecf0028" ,
159+ ),
160+ (FullBackupOptions (name = "Test" , background = False , extra = None ), "9ecf0028" ),
148161 (None , "9ecf0028" ),
149162 ],
150163)
@@ -165,23 +178,67 @@ async def test_backups_full_backup(
165178
166179
167180@pytest .mark .parametrize (
168- ("background" , "slug" ),
169- [(True , None ), (False , "9ecf0028" )],
181+ ("options" , "slug" ),
182+ [
183+ (PartialBackupOptions (name = "Test" , background = True , addons = {"core_ssh" }), None ),
184+ (
185+ PartialBackupOptions (name = "Test" , background = False , addons = {"core_ssh" }),
186+ "9ecf0028" ,
187+ ),
188+ (
189+ PartialBackupOptions (
190+ name = "Test" , background = False , location = None , addons = {"core_ssh" }
191+ ),
192+ "9ecf0028" ,
193+ ),
194+ (
195+ PartialBackupOptions (
196+ name = "Test" , background = False , location = "test" , addons = {"core_ssh" }
197+ ),
198+ "9ecf0028" ,
199+ ),
200+ (
201+ PartialBackupOptions (
202+ name = "Test" ,
203+ background = False ,
204+ location = {None , "test" },
205+ addons = {"core_ssh" },
206+ ),
207+ "9ecf0028" ,
208+ ),
209+ (
210+ PartialBackupOptions (
211+ name = "Test" ,
212+ background = False ,
213+ addons = {"core_ssh" },
214+ extra = {"user" : "test" , "scheduled" : True },
215+ ),
216+ "9ecf0028" ,
217+ ),
218+ (
219+ PartialBackupOptions (
220+ name = "Test" , background = False , addons = {"core_ssh" }, extra = None
221+ ),
222+ "9ecf0028" ,
223+ ),
224+ (
225+ PartialBackupOptions (name = "Test" , background = None , addons = {"core_ssh" }),
226+ "9ecf0028" ,
227+ ),
228+ ],
170229)
171230async def test_backups_partial_backup (
172231 responses : aioresponses ,
173232 supervisor_client : SupervisorClient ,
174- background : bool , # noqa: FBT001
233+ options : PartialBackupOptions ,
175234 slug : str | None ,
176235) -> None :
177236 """Test backups full backup API."""
178237 responses .post (
179238 f"{ SUPERVISOR_URL } /backups/new/partial" ,
180239 callback = backup_callback ,
181240 )
182- result = await supervisor_client .backups .partial_backup (
183- PartialBackupOptions (name = "test" , background = background , addons = {"core_ssh" })
184- )
241+ result = await supervisor_client .backups .partial_backup (options )
185242 assert result .job_id == "dc9dbc16f6ad4de592ffa72c807ca2bf"
186243 assert result .slug == slug
187244
@@ -200,6 +257,7 @@ async def test_backup_info(
200257 assert result .type == "partial"
201258 assert result .date == datetime (2024 , 5 , 31 , 0 , 0 , 0 , 0 , UTC )
202259 assert result .size == 0.01
260+ assert result .size_bytes == 10123
203261 assert result .compressed is True
204262 assert result .addons [0 ].slug == "core_mosquitto"
205263 assert result .addons [0 ].name == "Mosquitto broker"
@@ -214,6 +272,9 @@ async def test_backup_info(
214272 ]
215273 assert result .folders == []
216274 assert result .homeassistant_exclude_database is None
275+ assert result .extra is None
276+ assert result .location is None
277+ assert result .locations == {None }
217278
218279
219280async def test_backup_info_no_homeassistant (
@@ -231,6 +292,37 @@ async def test_backup_info_no_homeassistant(
231292 assert result .homeassistant is None
232293
233294
295+ async def test_backup_info_with_extra (
296+ responses : aioresponses , supervisor_client : SupervisorClient
297+ ) -> None :
298+ """Test backup info API with extras set by client."""
299+ responses .get (
300+ f"{ SUPERVISOR_URL } /backups/d13dedd0/info" ,
301+ status = 200 ,
302+ body = load_fixture ("backup_info_with_extra.json" ),
303+ )
304+ result = await supervisor_client .backups .backup_info ("d13dedd0" )
305+ assert result .slug == "69558789"
306+ assert result .type == "partial"
307+ assert result .extra == {"user" : "test" , "scheduled" : True }
308+
309+
310+ async def test_backup_info_with_multiple_locations (
311+ responses : aioresponses , supervisor_client : SupervisorClient
312+ ) -> None :
313+ """Test backup info API with multiple locations."""
314+ responses .get (
315+ f"{ SUPERVISOR_URL } /backups/d13dedd0/info" ,
316+ status = 200 ,
317+ body = load_fixture ("backup_info_with_locations.json" ),
318+ )
319+ result = await supervisor_client .backups .backup_info ("d13dedd0" )
320+ assert result .slug == "69558789"
321+ assert result .type == "partial"
322+ assert result .location is None
323+ assert result .locations == {None , "Test" }
324+
325+
234326async def test_remove_backup (
235327 responses : aioresponses , supervisor_client : SupervisorClient
236328) -> None :
0 commit comments