File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed
homeassistant/components/cloud Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change 77import hashlib
88from typing import Any , Self
99
10- from aiohttp import ClientError , StreamReader
10+ from aiohttp import ClientError , ClientTimeout , StreamReader
1111from hass_nabucasa import Cloud , CloudError
1212from hass_nabucasa .cloud_api import (
1313 async_files_delete_file ,
@@ -151,9 +151,10 @@ async def async_upload_backup(
151151 details ["url" ],
152152 data = await open_stream (),
153153 headers = details ["headers" ] | {"content-length" : str (backup .size )},
154+ timeout = ClientTimeout (connect = 10.0 , total = 43200.0 ), # 43200s == 12h
154155 )
155156 upload_status .raise_for_status ()
156- except ClientError as err :
157+ except ( TimeoutError , ClientError ) as err :
157158 raise BackupAgentError ("Failed to upload backup" ) from err
158159
159160 async def async_delete_backup (
Original file line number Diff line number Diff line change @@ -372,13 +372,15 @@ async def test_agents_upload(
372372 assert f"Uploading backup { backup_id } " in caplog .text
373373
374374
375+ @pytest .mark .parametrize ("put_mock_kwargs" , [{"status" : 500 }, {"exc" : TimeoutError }])
375376@pytest .mark .usefixtures ("cloud_logged_in" , "mock_list_files" )
376377async def test_agents_upload_fail_put (
377378 hass : HomeAssistant ,
378379 hass_client : ClientSessionGenerator ,
379380 caplog : pytest .LogCaptureFixture ,
380381 aioclient_mock : AiohttpClientMocker ,
381382 mock_get_upload_details : Mock ,
383+ put_mock_kwargs : dict [str , Any ],
382384) -> None :
383385 """Test agent upload backup fails."""
384386 client = await hass_client ()
@@ -395,7 +397,7 @@ async def test_agents_upload_fail_put(
395397 protected = True ,
396398 size = 0.0 ,
397399 )
398- aioclient_mock .put (mock_get_upload_details .return_value ["url" ], status = 500 )
400+ aioclient_mock .put (mock_get_upload_details .return_value ["url" ], ** put_mock_kwargs )
399401
400402 with (
401403 patch (
You can’t perform that action at this time.
0 commit comments