mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Use resumable uploads in Google Drive (#138010)
* Use resumable uploads in Google Drive * tests
This commit is contained in:
parent
6fe47a0f1b
commit
0bd161a45a
@ -146,9 +146,10 @@ class DriveClient:
|
|||||||
backup.backup_id,
|
backup.backup_id,
|
||||||
backup_metadata,
|
backup_metadata,
|
||||||
)
|
)
|
||||||
await self._api.upload_file(
|
await self._api.resumable_upload_file(
|
||||||
backup_metadata,
|
backup_metadata,
|
||||||
open_stream,
|
open_stream,
|
||||||
|
backup.size,
|
||||||
timeout=ClientTimeout(total=_UPLOAD_AND_DOWNLOAD_TIMEOUT),
|
timeout=ClientTimeout(total=_UPLOAD_AND_DOWNLOAD_TIMEOUT),
|
||||||
)
|
)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["google_drive_api"],
|
"loggers": ["google_drive_api"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["python-google-drive-api==0.0.2"]
|
"requirements": ["python-google-drive-api==0.1.0"]
|
||||||
}
|
}
|
||||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -2391,7 +2391,7 @@ python-gc100==1.0.3a0
|
|||||||
python-gitlab==1.6.0
|
python-gitlab==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.google_drive
|
# homeassistant.components.google_drive
|
||||||
python-google-drive-api==0.0.2
|
python-google-drive-api==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.analytics_insights
|
# homeassistant.components.analytics_insights
|
||||||
python-homeassistant-analytics==0.9.0
|
python-homeassistant-analytics==0.9.0
|
||||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -1936,7 +1936,7 @@ python-fullykiosk==0.0.14
|
|||||||
# python-gammu==3.2.4
|
# python-gammu==3.2.4
|
||||||
|
|
||||||
# homeassistant.components.google_drive
|
# homeassistant.components.google_drive
|
||||||
python-google-drive-api==0.0.2
|
python-google-drive-api==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.analytics_insights
|
# homeassistant.components.analytics_insights
|
||||||
python-homeassistant-analytics==0.9.0
|
python-homeassistant-analytics==0.9.0
|
||||||
|
@ -136,7 +136,7 @@
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
tuple(
|
tuple(
|
||||||
'upload_file',
|
'resumable_upload_file',
|
||||||
tuple(
|
tuple(
|
||||||
dict({
|
dict({
|
||||||
'description': '{"addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", "date": "2025-01-01T01:23:45.678Z", "database_included": true, "extra_metadata": {"with_automatic_settings": false}, "folders": [], "homeassistant_included": true, "homeassistant_version": "2024.12.0", "name": "Test", "protected": false, "size": 987}',
|
'description': '{"addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", "date": "2025-01-01T01:23:45.678Z", "database_included": true, "extra_metadata": {"with_automatic_settings": false}, "folders": [], "homeassistant_included": true, "homeassistant_version": "2024.12.0", "name": "Test", "protected": false, "size": 987}',
|
||||||
@ -151,6 +151,7 @@
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
"CoreBackupReaderWriter.async_receive_backup.<locals>.open_backup() -> 'AsyncIterator[bytes]'",
|
"CoreBackupReaderWriter.async_receive_backup.<locals>.open_backup() -> 'AsyncIterator[bytes]'",
|
||||||
|
987,
|
||||||
),
|
),
|
||||||
dict({
|
dict({
|
||||||
'timeout': dict({
|
'timeout': dict({
|
||||||
@ -207,7 +208,7 @@
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
tuple(
|
tuple(
|
||||||
'upload_file',
|
'resumable_upload_file',
|
||||||
tuple(
|
tuple(
|
||||||
dict({
|
dict({
|
||||||
'description': '{"addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", "date": "2025-01-01T01:23:45.678Z", "database_included": true, "extra_metadata": {"with_automatic_settings": false}, "folders": [], "homeassistant_included": true, "homeassistant_version": "2024.12.0", "name": "Test", "protected": false, "size": 987}',
|
'description': '{"addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", "date": "2025-01-01T01:23:45.678Z", "database_included": true, "extra_metadata": {"with_automatic_settings": false}, "folders": [], "homeassistant_included": true, "homeassistant_version": "2024.12.0", "name": "Test", "protected": false, "size": 987}',
|
||||||
@ -222,6 +223,7 @@
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
"CoreBackupReaderWriter.async_receive_backup.<locals>.open_backup() -> 'AsyncIterator[bytes]'",
|
"CoreBackupReaderWriter.async_receive_backup.<locals>.open_backup() -> 'AsyncIterator[bytes]'",
|
||||||
|
987,
|
||||||
),
|
),
|
||||||
dict({
|
dict({
|
||||||
'timeout': dict({
|
'timeout': dict({
|
||||||
|
@ -281,7 +281,7 @@ async def test_agents_upload(
|
|||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test agent upload backup."""
|
"""Test agent upload backup."""
|
||||||
mock_api.upload_file = AsyncMock(return_value=None)
|
mock_api.resumable_upload_file = AsyncMock(return_value=None)
|
||||||
|
|
||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ async def test_agents_upload(
|
|||||||
assert f"Uploading backup: {TEST_AGENT_BACKUP.backup_id}" in caplog.text
|
assert f"Uploading backup: {TEST_AGENT_BACKUP.backup_id}" in caplog.text
|
||||||
assert f"Uploaded backup: {TEST_AGENT_BACKUP.backup_id}" in caplog.text
|
assert f"Uploaded backup: {TEST_AGENT_BACKUP.backup_id}" in caplog.text
|
||||||
|
|
||||||
mock_api.upload_file.assert_called_once()
|
mock_api.resumable_upload_file.assert_called_once()
|
||||||
assert [tuple(mock_call) for mock_call in mock_api.mock_calls] == snapshot
|
assert [tuple(mock_call) for mock_call in mock_api.mock_calls] == snapshot
|
||||||
|
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ async def test_agents_upload_create_folder_if_missing(
|
|||||||
mock_api.create_file = AsyncMock(
|
mock_api.create_file = AsyncMock(
|
||||||
return_value={"id": "new folder id", "name": "Home Assistant"}
|
return_value={"id": "new folder id", "name": "Home Assistant"}
|
||||||
)
|
)
|
||||||
mock_api.upload_file = AsyncMock(return_value=None)
|
mock_api.resumable_upload_file = AsyncMock(return_value=None)
|
||||||
|
|
||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ async def test_agents_upload_create_folder_if_missing(
|
|||||||
assert f"Uploaded backup: {TEST_AGENT_BACKUP.backup_id}" in caplog.text
|
assert f"Uploaded backup: {TEST_AGENT_BACKUP.backup_id}" in caplog.text
|
||||||
|
|
||||||
mock_api.create_file.assert_called_once()
|
mock_api.create_file.assert_called_once()
|
||||||
mock_api.upload_file.assert_called_once()
|
mock_api.resumable_upload_file.assert_called_once()
|
||||||
assert [tuple(mock_call) for mock_call in mock_api.mock_calls] == snapshot
|
assert [tuple(mock_call) for mock_call in mock_api.mock_calls] == snapshot
|
||||||
|
|
||||||
|
|
||||||
@ -359,7 +359,9 @@ async def test_agents_upload_fail(
|
|||||||
mock_api: MagicMock,
|
mock_api: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test agent upload backup fails."""
|
"""Test agent upload backup fails."""
|
||||||
mock_api.upload_file = AsyncMock(side_effect=GoogleDriveApiError("some error"))
|
mock_api.resumable_upload_file = AsyncMock(
|
||||||
|
side_effect=GoogleDriveApiError("some error")
|
||||||
|
)
|
||||||
|
|
||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user