mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Refactor template image (#95353)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user