Skip to content

Commit 92b402c

Browse files
committed
test_url_fetch_error
1 parent e29e809 commit 92b402c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/test_init.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import voluptuous as vol
1616
import voluptuous.error as vol_error
1717
import yaml
18+
from aiohttp.client_exceptions import ClientResponseError
1819
from homeassistant.const import (
1920
CONF_BASE,
2021
CONF_DELAY,
@@ -323,6 +324,40 @@ async def test_invalid_config(
323324
assert "not a file @ data['patch']['files'][0]" in str(err.value)
324325

325326

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+
326361
async def test_no_delay(
327362
hass: HomeAssistant,
328363
) -> None:

0 commit comments

Comments
 (0)