Use async with to fetch HTTP streams in tests (#82788)
This commit is contained in:
parent
444ad52757
commit
31ad208500
2 changed files with 23 additions and 21 deletions
|
@ -327,7 +327,7 @@ async def test_stream(hass, mock_api_client):
|
||||||
"""Test the stream."""
|
"""Test the stream."""
|
||||||
listen_count = _listen_count(hass)
|
listen_count = _listen_count(hass)
|
||||||
|
|
||||||
resp = await mock_api_client.get(const.URL_API_STREAM)
|
async with mock_api_client.get(const.URL_API_STREAM) as resp:
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
assert listen_count + 1 == _listen_count(hass)
|
assert listen_count + 1 == _listen_count(hass)
|
||||||
|
|
||||||
|
@ -342,9 +342,9 @@ async def test_stream_with_restricted(hass, mock_api_client):
|
||||||
"""Test the stream with restrictions."""
|
"""Test the stream with restrictions."""
|
||||||
listen_count = _listen_count(hass)
|
listen_count = _listen_count(hass)
|
||||||
|
|
||||||
resp = await mock_api_client.get(
|
async with mock_api_client.get(
|
||||||
f"{const.URL_API_STREAM}?restrict=test_event1,test_event3"
|
f"{const.URL_API_STREAM}?restrict=test_event1,test_event3"
|
||||||
)
|
) as resp:
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
assert listen_count + 1 == _listen_count(hass)
|
assert listen_count + 1 == _listen_count(hass)
|
||||||
|
|
||||||
|
|
|
@ -503,14 +503,16 @@ async def test_camera_proxy_stream(hass, mock_camera, hass_client):
|
||||||
|
|
||||||
client = await hass_client()
|
client = await hass_client()
|
||||||
|
|
||||||
response = await client.get("/api/camera_proxy_stream/camera.demo_camera")
|
async with client.get("/api/camera_proxy_stream/camera.demo_camera") as response:
|
||||||
assert response.status == HTTPStatus.OK
|
assert response.status == HTTPStatus.OK
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.demo.camera.DemoCamera.handle_async_mjpeg_stream",
|
"homeassistant.components.demo.camera.DemoCamera.handle_async_mjpeg_stream",
|
||||||
return_value=None,
|
return_value=None,
|
||||||
):
|
):
|
||||||
response = await client.get("/api/camera_proxy_stream/camera.demo_camera")
|
async with await client.get(
|
||||||
|
"/api/camera_proxy_stream/camera.demo_camera"
|
||||||
|
) as response:
|
||||||
assert response.status == HTTPStatus.BAD_GATEWAY
|
assert response.status == HTTPStatus.BAD_GATEWAY
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue