diff --git a/homeassistant/components/onedrive/backup.py b/homeassistant/components/onedrive/backup.py index 5dd7038f2112..fdec23a6da25 100644 --- a/homeassistant/components/onedrive/backup.py +++ b/homeassistant/components/onedrive/backup.py @@ -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( diff --git a/homeassistant/components/onedrive_for_business/backup.py b/homeassistant/components/onedrive_for_business/backup.py index bec7dfd8c3e2..dc35ae797431 100644 --- a/homeassistant/components/onedrive_for_business/backup.py +++ b/homeassistant/components/onedrive_for_business/backup.py @@ -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( diff --git a/tests/components/onedrive/test_backup.py b/tests/components/onedrive/test_backup.py index d15cfcfa6c60..8514c19f82b1 100644 --- a/tests/components/onedrive/test_backup.py +++ b/tests/components/onedrive/test_backup.py @@ -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 diff --git a/tests/components/onedrive_for_business/test_backup.py b/tests/components/onedrive_for_business/test_backup.py index 84cc0383778d..96250c5780fa 100644 --- a/tests/components/onedrive_for_business/test_backup.py +++ b/tests/components/onedrive_for_business/test_backup.py @@ -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