|
12 | 12 | from aiohasupervisor import SupervisorClient |
13 | 13 | from aiohasupervisor.models import ( |
14 | 14 | BackupsOptions, |
| 15 | + DownloadBackupOptions, |
15 | 16 | Folder, |
16 | 17 | FreezeOptions, |
17 | 18 | FullBackupOptions, |
18 | 19 | PartialBackupOptions, |
19 | 20 | PartialRestoreOptions, |
| 21 | + RemoveBackupOptions, |
20 | 22 | UploadBackupOptions, |
21 | 23 | ) |
22 | 24 |
|
@@ -131,6 +133,32 @@ async def test_partial_restore_options() -> None: |
131 | 133 | PartialRestoreOptions(background=True) |
132 | 134 |
|
133 | 135 |
|
| 136 | +async def test_backup_options_location() -> None: |
| 137 | + """Test location field in backup options.""" |
| 138 | + assert FullBackupOptions(location=["test", None]).to_dict() == { |
| 139 | + "location": ["test", None] |
| 140 | + } |
| 141 | + assert FullBackupOptions(location="test").to_dict() == {"location": "test"} |
| 142 | + assert FullBackupOptions(location=None).to_dict() == {"location": None} |
| 143 | + assert FullBackupOptions().to_dict() == {} |
| 144 | + |
| 145 | + assert PartialBackupOptions( |
| 146 | + location=["test", None], folders={Folder.SSL} |
| 147 | + ).to_dict() == { |
| 148 | + "location": ["test", None], |
| 149 | + "folders": ["ssl"], |
| 150 | + } |
| 151 | + assert PartialBackupOptions(location="test", folders={Folder.SSL}).to_dict() == { |
| 152 | + "location": "test", |
| 153 | + "folders": ["ssl"], |
| 154 | + } |
| 155 | + assert PartialBackupOptions(location=None, folders={Folder.SSL}).to_dict() == { |
| 156 | + "location": None, |
| 157 | + "folders": ["ssl"], |
| 158 | + } |
| 159 | + assert PartialBackupOptions(folders={Folder.SSL}).to_dict() == {"folders": ["ssl"]} |
| 160 | + |
| 161 | + |
134 | 162 | def backup_callback(url: str, **kwargs: dict[str, Any]) -> CallbackResult: # noqa: ARG001 |
135 | 163 | """Return response based on whether backup was in background or not.""" |
136 | 164 | if kwargs["json"] and kwargs["json"].get("background"): |
@@ -323,12 +351,17 @@ async def test_backup_info_with_multiple_locations( |
323 | 351 | assert result.locations == {None, "Test"} |
324 | 352 |
|
325 | 353 |
|
| 354 | +@pytest.mark.parametrize( |
| 355 | + "options", [None, RemoveBackupOptions(location={"test", None})] |
| 356 | +) |
326 | 357 | async def test_remove_backup( |
327 | | - responses: aioresponses, supervisor_client: SupervisorClient |
| 358 | + responses: aioresponses, |
| 359 | + supervisor_client: SupervisorClient, |
| 360 | + options: RemoveBackupOptions | None, |
328 | 361 | ) -> None: |
329 | 362 | """Test remove backup API.""" |
330 | 363 | responses.delete(f"{SUPERVISOR_URL}/backups/abc123", status=200) |
331 | | - assert await supervisor_client.backups.remove_backup("abc123") is None |
| 364 | + assert await supervisor_client.backups.remove_backup("abc123", options) is None |
332 | 365 | assert responses.requests.keys() == { |
333 | 366 | ("DELETE", URL(f"{SUPERVISOR_URL}/backups/abc123")) |
334 | 367 | } |
@@ -398,14 +431,27 @@ async def test_upload_backup_to_locations( |
398 | 431 | assert result == "7fed74c8" |
399 | 432 |
|
400 | 433 |
|
| 434 | +@pytest.mark.parametrize( |
| 435 | + ("options", "query"), |
| 436 | + [ |
| 437 | + (None, ""), |
| 438 | + (DownloadBackupOptions(location="test"), "?location=test"), |
| 439 | + (DownloadBackupOptions(location=None), "?location="), |
| 440 | + ], |
| 441 | +) |
401 | 442 | async def test_download_backup( |
402 | | - responses: aioresponses, supervisor_client: SupervisorClient |
| 443 | + responses: aioresponses, |
| 444 | + supervisor_client: SupervisorClient, |
| 445 | + options: DownloadBackupOptions | None, |
| 446 | + query: str, |
403 | 447 | ) -> None: |
404 | 448 | """Test download backup API.""" |
405 | 449 | responses.get( |
406 | | - f"{SUPERVISOR_URL}/backups/7fed74c8/download", status=200, body=b"backup test" |
| 450 | + f"{SUPERVISOR_URL}/backups/7fed74c8/download{query}", |
| 451 | + status=200, |
| 452 | + body=b"backup test", |
407 | 453 | ) |
408 | | - result = await supervisor_client.backups.download_backup("7fed74c8") |
| 454 | + result = await supervisor_client.backups.download_backup("7fed74c8", options) |
409 | 455 | assert isinstance(result, AsyncIterator) |
410 | 456 | async for chunk in result: |
411 | 457 | assert chunk == b"backup test" |
0 commit comments