Use async with to fetch HTTP streams in tests (#82788)

This commit is contained in:
uvjustin 2022-11-28 03:35:03 +08:00 committed by GitHub
parent 444ad52757
commit 31ad208500
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 21 deletions

View file

@ -327,7 +327,7 @@ async def test_stream(hass, mock_api_client):
"""Test the stream."""
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 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."""
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"
)
) as resp:
assert resp.status == HTTPStatus.OK
assert listen_count + 1 == _listen_count(hass)

View file

@ -503,14 +503,16 @@ async def test_camera_proxy_stream(hass, mock_camera, 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
with patch(
"homeassistant.components.demo.camera.DemoCamera.handle_async_mjpeg_stream",
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