hass-core/tests/components/ezviz/conftest.py
RenierM26 93d1961aae
Use auth token in Ezviz (#54663)
* Initial commit

* Revert "Initial commit"

This reverts commit 452027f1a3c1be186cedd4115cea6928917c9467.

* Change ezviz to token auth

* Bump API version.

* Add fix for token expired. Fix options update and unload.

* Fix tests (PLATFORM to PLATFORM_BY_TYPE)

* Uses and stores token only, added reauth step when token expires.

* Add tests MFA code exceptions.

* Fix tests.

* Remove redundant try/except blocks.

* Rebase fixes.

* Fix errors in reauth config flow

* Implement recommendations

* Fix typing error in config_flow

* Fix tests after rebase, readd camera check on init

* Change to platform setup

* Cleanup init.

* Test for MFA required under user form

* Remove useless if block.

* Fix formating after rebase

* Fix formating.

* No longer stored in the repository

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2023-03-29 17:43:54 -04:00

54 lines
1.6 KiB
Python

"""Define pytest.fixtures available for all tests."""
from unittest.mock import MagicMock, patch
from pyezviz import EzvizClient
from pyezviz.test_cam_rtsp import TestRTSPAuth
import pytest
ezviz_login_token_return = {
"session_id": "fake_token",
"rf_session_id": "fake_rf_token",
"api_url": "apiieu.ezvizlife.com",
}
@pytest.fixture(autouse=True)
def mock_ffmpeg(hass):
"""Mock ffmpeg is loaded."""
hass.config.components.add("ffmpeg")
@pytest.fixture
def ezviz_test_rtsp_config_flow(hass):
"""Mock the EzvizApi for easier testing."""
with patch.object(TestRTSPAuth, "main", return_value=True), patch(
"homeassistant.components.ezviz.config_flow.TestRTSPAuth"
) as mock_ezviz_test_rtsp:
instance = mock_ezviz_test_rtsp.return_value = TestRTSPAuth(
"test-ip",
"test-username",
"test-password",
)
instance.main = MagicMock(return_value=True)
yield mock_ezviz_test_rtsp
@pytest.fixture
def ezviz_config_flow(hass):
"""Mock the EzvizAPI for easier config flow testing."""
with patch.object(EzvizClient, "login", return_value=True), patch(
"homeassistant.components.ezviz.config_flow.EzvizClient"
) as mock_ezviz:
instance = mock_ezviz.return_value = EzvizClient(
"test-username",
"test-password",
"local.host",
"1",
)
instance.login = MagicMock(return_value=ezviz_login_token_return)
instance.get_detection_sensibility = MagicMock(return_value=True)
yield mock_ezviz