|
15 | 15 | import voluptuous as vol |
16 | 16 | import voluptuous.error as vol_error |
17 | 17 | import yaml |
| 18 | +from aiohttp.client_exceptions import ClientResponseError |
18 | 19 | from homeassistant.const import ( |
19 | 20 | CONF_BASE, |
20 | 21 | CONF_DELAY, |
@@ -323,6 +324,40 @@ async def test_invalid_config( |
323 | 324 | assert "not a file @ data['patch']['files'][0]" in str(err.value) |
324 | 325 |
|
325 | 326 |
|
| 327 | +async def test_url_fetch_error( |
| 328 | + hass: HomeAssistant, |
| 329 | + freezer: FrozenDateTimeFactory, |
| 330 | + aioclient_mock: AiohttpClientMocker, |
| 331 | +) -> None: |
| 332 | + """Test URL download error.""" |
| 333 | + aioclient_mock.get("https://test.com/file", status=404) |
| 334 | + with tempfile.TemporaryDirectory() as dest_dir: |
| 335 | + destination = Path(dest_dir) / "file" |
| 336 | + with (destination).open("w", encoding="ascii") as file: |
| 337 | + file.write("test") |
| 338 | + await async_setup(hass, {CONF_FILES: []}) |
| 339 | + await async_next_day(hass, freezer) |
| 340 | + with ( |
| 341 | + patch( |
| 342 | + "homeassistant.config.load_yaml_config_file", |
| 343 | + return_value={ |
| 344 | + DOMAIN: { |
| 345 | + CONF_FILES: [ |
| 346 | + { |
| 347 | + CONF_DESTINATION: destination, |
| 348 | + CONF_BASE: "https://test.com/file", |
| 349 | + CONF_PATCH: "https://test.com/file", |
| 350 | + } |
| 351 | + ] |
| 352 | + } |
| 353 | + }, |
| 354 | + ), |
| 355 | + pytest.raises(ClientResponseError) as error, |
| 356 | + ): |
| 357 | + await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True) |
| 358 | + assert error.value.status == 404 |
| 359 | + |
| 360 | + |
326 | 361 | async def test_no_delay( |
327 | 362 | hass: HomeAssistant, |
328 | 363 | ) -> None: |
|
0 commit comments