Refactor template image (#95353)

This commit is contained in:
Erik Montnemery
2023-06-27 18:46:36 +02:00
committed by GitHub
parent 1a8bc1930c
commit 68db751ce1
2 changed files with 11 additions and 126 deletions

View File

@@ -279,78 +279,6 @@ async def test_custom_entity_picture(
)
@respx.mock
@pytest.mark.freeze_time("2023-04-01 00:00:00+00:00")
async def test_http_error(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test handling http error."""
respx.get("http://example.com").respond(HTTPStatus.NOT_FOUND)
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
hass,
"template",
{
"template": {
"image": {
"url": "http://example.com",
},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
expected_state = dt_util.utcnow().isoformat()
await _assert_state(
hass,
hass_client,
expected_state,
b"500: Internal Server Error",
expected_status=HTTPStatus.INTERNAL_SERVER_ERROR,
expected_content_type="text/plain",
)
@respx.mock
@pytest.mark.freeze_time("2023-04-01 00:00:00+00:00")
async def test_http_timeout(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test handling http timeout."""
respx.get("http://example.com").side_effect = httpx.TimeoutException
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
hass,
"template",
{
"template": {
"image": {
"url": "http://example.com",
},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
expected_state = dt_util.utcnow().isoformat()
await _assert_state(
hass,
hass_client,
expected_state,
b"500: Internal Server Error",
expected_status=HTTPStatus.INTERNAL_SERVER_ERROR,
expected_content_type="text/plain",
)
@respx.mock
async def test_template_error(
hass: HomeAssistant, hass_client: ClientSessionGenerator