-
-
Notifications
You must be signed in to change notification settings - Fork 381
Next release #1615
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
Merged
Next release #1615
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
98a1ac1
Merge pull request #1614 from netalertx/main
jokob-sk 285bd3e
Enhance device filters: support label for dropdown options and improv…
jokob-sk 89139fe
Add update_sync_hub_node function and corresponding tests for backfil…
jokob-sk c046298
BE: feedback + unify null / empty checks
jokob-sk 7c7beaa
BE: empty checks fix
jokob-sk f9bd8f3
Refactor test_sync_hub_node_backfill: streamline imports and utilize …
jokob-sk a5b4f2a
Merge branch 'next_release' of https://github.com/netalertx/NetAlertX…
jokob-sk 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
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
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
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,90 @@ | ||
| """Tests for update_sync_hub_node backfill.""" | ||
|
|
||
| import sys | ||
| import os | ||
| from unittest.mock import patch | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | ||
| from db_test_helpers import make_db, DummyDB # noqa: E402 | ||
|
|
||
| from server.scan import device_handling | ||
|
|
||
|
|
||
| def _make_db(devices): | ||
| """Create an in-memory DB with full schema and seed rows.""" | ||
| conn = make_db() | ||
| cur = conn.cursor() | ||
| cur.executemany( | ||
| "INSERT INTO Devices (devMac, devSyncHubNode) VALUES (?, ?)", | ||
| devices, | ||
| ) | ||
| conn.commit() | ||
| return conn | ||
|
|
||
|
|
||
| def _read_nodes(conn): | ||
| """Return a dict of devMac -> devSyncHubNode.""" | ||
| return { | ||
| row["devMac"]: row["devSyncHubNode"] | ||
| for row in conn.execute("SELECT devMac, devSyncHubNode FROM Devices") | ||
| } | ||
|
|
||
|
|
||
| @patch.object(device_handling, "get_setting_value", return_value="MyNode") | ||
| def test_backfill_empty_values(mock_setting): | ||
| """Empty and null devSyncHubNode should be backfilled with SYNC_node_name.""" | ||
| conn = _make_db([ | ||
| ("AA:AA:AA:AA:AA:01", ""), | ||
| ("AA:AA:AA:AA:AA:02", None), | ||
| ("AA:AA:AA:AA:AA:03", "null"), | ||
| ]) | ||
|
|
||
| device_handling.update_sync_hub_node(DummyDB(conn)) | ||
| nodes = _read_nodes(conn) | ||
|
|
||
| assert nodes["AA:AA:AA:AA:AA:01"] == "MyNode" | ||
| assert nodes["AA:AA:AA:AA:AA:02"] == "MyNode" | ||
| assert nodes["AA:AA:AA:AA:AA:03"] == "MyNode" | ||
|
|
||
|
|
||
| @patch.object(device_handling, "get_setting_value", return_value="MyNode") | ||
| def test_no_overwrite_existing(mock_setting): | ||
| """Devices with a real devSyncHubNode should not be overwritten.""" | ||
| conn = _make_db([ | ||
| ("AA:AA:AA:AA:AA:01", "RemoteNode"), | ||
| ("AA:AA:AA:AA:AA:02", ""), | ||
| ]) | ||
|
|
||
| device_handling.update_sync_hub_node(DummyDB(conn)) | ||
| nodes = _read_nodes(conn) | ||
|
|
||
| assert nodes["AA:AA:AA:AA:AA:01"] == "RemoteNode" | ||
| assert nodes["AA:AA:AA:AA:AA:02"] == "MyNode" | ||
|
|
||
|
|
||
| @patch.object(device_handling, "get_setting_value", return_value="") | ||
| def test_noop_when_setting_empty(mock_setting): | ||
| """No updates when SYNC_node_name is empty.""" | ||
| conn = _make_db([ | ||
| ("AA:AA:AA:AA:AA:01", ""), | ||
| ("AA:AA:AA:AA:AA:02", None), | ||
| ]) | ||
|
|
||
| device_handling.update_sync_hub_node(DummyDB(conn)) | ||
| nodes = _read_nodes(conn) | ||
|
|
||
| assert nodes["AA:AA:AA:AA:AA:01"] == "" | ||
| assert nodes["AA:AA:AA:AA:AA:02"] is None | ||
|
|
||
|
|
||
| @patch.object(device_handling, "get_setting_value", return_value=None) | ||
| def test_noop_when_setting_none(mock_setting): | ||
| """No updates when SYNC_node_name is None.""" | ||
| conn = _make_db([ | ||
| ("AA:AA:AA:AA:AA:01", ""), | ||
| ]) | ||
|
|
||
| device_handling.update_sync_hub_node(DummyDB(conn)) | ||
| nodes = _read_nodes(conn) | ||
|
|
||
| assert nodes["AA:AA:AA:AA:AA:01"] == "" |
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.