Add backup progress callback to onedrive integrations (#165217)

This commit is contained in:
Josef Zweck
2026-03-15 16:31:04 +01:00
committed by GitHub
parent 4efbafb003
commit d7c2dfc4d4
4 changed files with 34 additions and 0 deletions
@@ -180,6 +180,9 @@ class OneDriveBackupAgent(BackupAgent):
upload_chunk_size=upload_chunk_size,
session=async_get_clientsession(self._hass),
smart_chunk_size=True,
progress_callback=lambda bytes_uploaded: on_progress(
bytes_uploaded=bytes_uploaded
),
)
except HashMismatchError as err:
raise BackupAgentError(
@@ -174,6 +174,9 @@ class OneDriveBackupAgent(BackupAgent):
upload_chunk_size=upload_chunk_size,
session=async_get_clientsession(self._hass),
smart_chunk_size=True,
progress_callback=lambda bytes_uploaded: on_progress(
bytes_uploaded=bytes_uploaded
),
)
except HashMismatchError as err:
raise BackupAgentError(
+12
View File
@@ -234,6 +234,10 @@ async def test_agents_upload(
assert resp.status == 201
assert f"Uploading backup {test_backup.backup_id}" in caplog.text
mock_large_file_upload_client.assert_called_once()
assert (
mock_large_file_upload_client.call_args.kwargs.get("progress_callback")
is not None
)
# upload_file should be called for the metadata file
mock_onedrive_client.upload_file.assert_called_once()
# update_drive_item should not be called (no description updates)
@@ -272,6 +276,10 @@ async def test_agents_upload_corrupt_upload(
assert resp.status == 201
assert f"Uploading backup {test_backup.backup_id}" in caplog.text
mock_large_file_upload_client.assert_called_once()
assert (
mock_large_file_upload_client.call_args.kwargs.get("progress_callback")
is not None
)
assert mock_onedrive_client.update_drive_item.call_count == 0
assert "Hash validation failed, backup file might be corrupt" in caplog.text
@@ -308,6 +316,10 @@ async def test_agents_upload_metadata_upload_failed(
assert resp.status == 201
assert f"Uploading backup {test_backup.backup_id}" in caplog.text
mock_large_file_upload_client.assert_called_once()
assert (
mock_large_file_upload_client.call_args.kwargs.get("progress_callback")
is not None
)
mock_onedrive_client.delete_drive_item.assert_called_once()
assert mock_onedrive_client.update_drive_item.call_count == 0
@@ -240,6 +240,14 @@ async def test_agents_upload(
assert resp.status == 201
assert f"Uploading backup {test_backup.backup_id}" in caplog.text
mock_large_file_upload_client.assert_called_once()
assert (
mock_large_file_upload_client.call_args.kwargs.get("progress_callback")
is not None
)
# upload_file should be called for the metadata file
mock_onedrive_client.upload_file.assert_called_once()
# update_drive_item should not be called (no description updates)
assert mock_onedrive_client.update_drive_item.call_count == 0
async def test_agents_upload_corrupt_upload(
@@ -274,6 +282,10 @@ async def test_agents_upload_corrupt_upload(
assert resp.status == 201
assert f"Uploading backup {test_backup.backup_id}" in caplog.text
mock_large_file_upload_client.assert_called_once()
assert (
mock_large_file_upload_client.call_args.kwargs.get("progress_callback")
is not None
)
assert mock_onedrive_client.update_drive_item.call_count == 0
assert "Hash validation failed, backup file might be corrupt" in caplog.text
@@ -310,6 +322,10 @@ async def test_agents_upload_metadata_upload_failed(
assert resp.status == 201
assert f"Uploading backup {test_backup.backup_id}" in caplog.text
mock_large_file_upload_client.assert_called_once()
assert (
mock_large_file_upload_client.call_args.kwargs.get("progress_callback")
is not None
)
mock_onedrive_client.delete_drive_item.assert_called_once()
assert mock_onedrive_client.update_drive_item.call_count == 0