Fix camera tests (#57020)

This commit is contained in:
Tobias Sauerwein 2021-10-04 01:55:07 +02:00 committed by GitHub
parent 3976443292
commit 1747578be5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -71,6 +71,17 @@ async def fake_post_request(*args, **kwargs):
)
async def fake_get_image(*args, **kwargs):
"""Return fake data."""
if "url" not in kwargs:
return "{}"
endpoint = kwargs["url"].split("/")[-1]
if endpoint in "snapshot_720.jpg":
return b"test stream image bytes"
async def fake_post_request_no_data(*args, **kwargs):
"""Fake error during requesting backend data."""
return "{}"

View File

@ -4,7 +4,7 @@ from unittest.mock import AsyncMock, patch
import pytest
from .common import ALL_SCOPES, fake_post_request
from .common import ALL_SCOPES, fake_get_image, fake_post_request
from tests.common import MockConfigEntry
@ -60,6 +60,7 @@ def netatmo_auth():
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth"
) as mock_auth:
mock_auth.return_value.async_post_request.side_effect = fake_post_request
mock_auth.return_value.async_get_image.side_effect = fake_get_image
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
mock_auth.return_value.async_dropwebhook.side_effect = AsyncMock()
yield

View File

@ -478,6 +478,7 @@ async def test_camera_image_raises_exception(hass, config_entry, requests_mock):
"homeassistant.components.webhook.async_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = fake_post
mock_auth.return_value.async_get_image.side_effect = fake_post
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
mock_auth.return_value.async_dropwebhook.side_effect = AsyncMock()