mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-30 23:03:03 -07:00
feat: Implement forced device status updates and enhance related tests
This commit is contained in:
@@ -33,6 +33,7 @@ def scan_db():
|
||||
devMac TEXT PRIMARY KEY,
|
||||
devLastConnection TEXT,
|
||||
devPresentLastScan INTEGER DEFAULT 0,
|
||||
devForceStatus TEXT,
|
||||
devLastIP TEXT,
|
||||
devName TEXT,
|
||||
devNameSource TEXT DEFAULT 'NEWDEV',
|
||||
@@ -93,6 +94,7 @@ def mock_device_handlers():
|
||||
with patch.multiple(
|
||||
device_handling,
|
||||
update_devPresentLastScan_based_on_nics=Mock(return_value=0),
|
||||
update_devPresentLastScan_based_on_force_status=Mock(return_value=0),
|
||||
query_MAC_vendor=Mock(return_value=-1),
|
||||
guess_icon=Mock(return_value="icon"),
|
||||
guess_type=Mock(return_value="type"),
|
||||
|
||||
65
test/authoritative_fields/test_force_status.py
Normal file
65
test/authoritative_fields/test_force_status.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""Tests for forced device status updates."""
|
||||
|
||||
import sqlite3
|
||||
|
||||
from server.scan import device_handling
|
||||
|
||||
|
||||
class DummyDB:
|
||||
"""Minimal DB wrapper compatible with device_handling helpers."""
|
||||
|
||||
def __init__(self, conn):
|
||||
self.sql = conn.cursor()
|
||||
self._conn = conn
|
||||
|
||||
def commitDB(self):
|
||||
self._conn.commit()
|
||||
|
||||
|
||||
def test_force_status_updates_present_flag():
|
||||
"""Forced status should override devPresentLastScan for online/offline values."""
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.row_factory = sqlite3.Row
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
CREATE TABLE Devices (
|
||||
devMac TEXT PRIMARY KEY,
|
||||
devPresentLastScan INTEGER,
|
||||
devForceStatus TEXT
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
cur.executemany(
|
||||
"""
|
||||
INSERT INTO Devices (devMac, devPresentLastScan, devForceStatus)
|
||||
VALUES (?, ?, ?)
|
||||
""",
|
||||
[
|
||||
("AA:AA:AA:AA:AA:01", 0, "online"),
|
||||
("AA:AA:AA:AA:AA:02", 1, "offline"),
|
||||
("AA:AA:AA:AA:AA:03", 1, "dont_force"),
|
||||
("AA:AA:AA:AA:AA:04", 0, None),
|
||||
("AA:AA:AA:AA:AA:05", 0, "ONLINE"),
|
||||
],
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
db = DummyDB(conn)
|
||||
updated = device_handling.update_devPresentLastScan_based_on_force_status(db)
|
||||
|
||||
rows = {
|
||||
row["devMac"]: row["devPresentLastScan"]
|
||||
for row in cur.execute("SELECT devMac, devPresentLastScan FROM Devices")
|
||||
}
|
||||
|
||||
assert updated == 3
|
||||
assert rows["AA:AA:AA:AA:AA:01"] == 1
|
||||
assert rows["AA:AA:AA:AA:AA:02"] == 0
|
||||
assert rows["AA:AA:AA:AA:AA:03"] == 1
|
||||
assert rows["AA:AA:AA:AA:AA:04"] == 0
|
||||
assert rows["AA:AA:AA:AA:AA:05"] == 1
|
||||
|
||||
conn.close()
|
||||
@@ -29,6 +29,7 @@ def ip_test_db():
|
||||
devMac TEXT PRIMARY KEY,
|
||||
devLastConnection TEXT,
|
||||
devPresentLastScan INTEGER,
|
||||
devForceStatus TEXT,
|
||||
devLastIP TEXT,
|
||||
devLastIpSource TEXT DEFAULT 'NEWDEV',
|
||||
devPrimaryIPv4 TEXT,
|
||||
@@ -78,6 +79,7 @@ def mock_ip_handlers():
|
||||
with patch.multiple(
|
||||
device_handling,
|
||||
update_devPresentLastScan_based_on_nics=Mock(return_value=0),
|
||||
update_devPresentLastScan_based_on_force_status=Mock(return_value=0),
|
||||
query_MAC_vendor=Mock(return_value=-1),
|
||||
guess_icon=Mock(return_value="icon"),
|
||||
guess_type=Mock(return_value="type"),
|
||||
|
||||
@@ -23,6 +23,7 @@ def in_memory_db():
|
||||
devMac TEXT PRIMARY KEY,
|
||||
devLastConnection TEXT,
|
||||
devPresentLastScan INTEGER,
|
||||
devForceStatus TEXT,
|
||||
devLastIP TEXT,
|
||||
devPrimaryIPv4 TEXT,
|
||||
devPrimaryIPv6 TEXT,
|
||||
@@ -69,6 +70,7 @@ def mock_device_handling():
|
||||
with patch.multiple(
|
||||
device_handling,
|
||||
update_devPresentLastScan_based_on_nics=Mock(return_value=0),
|
||||
update_devPresentLastScan_based_on_force_status=Mock(return_value=0),
|
||||
query_MAC_vendor=Mock(return_value=-1),
|
||||
guess_icon=Mock(return_value="icon"),
|
||||
guess_type=Mock(return_value="type"),
|
||||
|
||||
Reference in New Issue
Block a user