-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Reolink test init 100% #89112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+279
−164
Merged
Reolink test init 100% #89112
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4c7e10c
Split out reolink tests
starkillerOG aaf8d48
Bring __init__ coverage to 100%
starkillerOG 8d6109d
Improve docstrings
starkillerOG 1a594e5
Use patching and autospec=True for ReolinkHost
starkillerOG 1e50301
Use fixture
starkillerOG 1aa9e68
fix styling
starkillerOG 495f7ed
Parametrize tests
starkillerOG 22397ab
Update tests/components/reolink/conftest.py
starkillerOG f28b378
Apply suggestions from code review
starkillerOG 856d7b3
Update test_config_flow.py
starkillerOG 74060b4
convert to fixture
starkillerOG 8d3e2d1
review comments
starkillerOG 5b3d91e
Update tests/components/reolink/conftest.py
starkillerOG 0f079fe
Update tests/components/reolink/conftest.py
starkillerOG e5721e1
Update tests/components/reolink/conftest.py
starkillerOG 86fbcc1
fix tests
starkillerOG 8434029
fix imports
starkillerOG b689a7a
Update test_init.py
starkillerOG 359fcff
Check if host is logout on reload
starkillerOG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Setup the Reolink tests.""" | ||
| from collections.abc import Generator | ||
| from unittest.mock import AsyncMock, Mock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| TEST_HOST = "1.2.3.4" | ||
| TEST_HOST2 = "4.5.6.7" | ||
| TEST_USERNAME = "admin" | ||
| TEST_USERNAME2 = "username" | ||
| TEST_PASSWORD = "password" | ||
| TEST_PASSWORD2 = "new_password" | ||
| TEST_MAC = "ab:cd:ef:gh:ij:kl" | ||
| TEST_PORT = 1234 | ||
| TEST_NVR_NAME = "test_reolink_name" | ||
| TEST_USE_HTTPS = True | ||
|
|
||
|
|
||
| def get_mock_info(error=None): | ||
| """Return a mock gateway info instance.""" | ||
| host_mock = Mock() | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| if error is None: | ||
| host_mock.get_host_data = AsyncMock(return_value=None) | ||
| else: | ||
| host_mock.get_host_data = AsyncMock(side_effect=error) | ||
| host_mock.get_states = AsyncMock(return_value=None) | ||
| host_mock.check_new_firmware = AsyncMock(return_value=False) | ||
| host_mock.unsubscribe = AsyncMock(return_value=True) | ||
| host_mock.logout = AsyncMock(return_value=True) | ||
| host_mock.mac_address = TEST_MAC | ||
| host_mock.onvif_enabled = True | ||
| host_mock.rtmp_enabled = True | ||
| host_mock.rtsp_enabled = True | ||
| host_mock.nvr_name = TEST_NVR_NAME | ||
| host_mock.port = TEST_PORT | ||
| host_mock.use_https = TEST_USE_HTTPS | ||
| host_mock.is_admin = True | ||
| host_mock.user_level = "admin" | ||
| host_mock.sw_version_update_required = False | ||
| host_mock.timeout = 60 | ||
| host_mock.renewtimer = 600 | ||
| return host_mock | ||
|
|
||
|
|
||
| @pytest.fixture(name="reolink_setup_entry") | ||
| def reolink_setup_entry_fixture() -> Generator[AsyncMock, None, None]: | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| """Override async_setup_entry.""" | ||
| with patch( | ||
| "homeassistant.components.reolink.async_setup_entry", return_value=True | ||
| ) as mock_setup_entry: | ||
| yield mock_setup_entry | ||
|
|
||
|
|
||
| @pytest.fixture(name="reolink_connect") | ||
| def reolink_connect_fixture(mock_get_source_ip): | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| """Mock reolink connection.""" | ||
| with patch( | ||
| "homeassistant.components.reolink.host.webhook.async_register", | ||
| return_value=True, | ||
| ), patch( | ||
| "homeassistant.components.reolink.host.Host", return_value=get_mock_info() | ||
| ): | ||
| yield | ||
|
|
||
|
|
||
| @pytest.fixture(name="reolink_init") | ||
| def reolink_init_fixture(mock_get_source_ip): | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| """Mock reolink entry setup.""" | ||
| with patch("homeassistant.components.reolink.PLATFORMS", return_value=[]): | ||
| yield | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.