diff --git a/.github/workflows/run-all-tests.yml b/.github/workflows/run-all-tests.yml index 14eca50f..45118577 100644 --- a/.github/workflows/run-all-tests.yml +++ b/.github/workflows/run-all-tests.yml @@ -3,8 +3,8 @@ name: ๐Ÿงช Manual Test Suite Selector on: workflow_dispatch: inputs: - run_authoritative: - description: '๐Ÿ“‚ authoritative_fields/ (Logic, Locks, IPs)' + run_scan: + description: '๐Ÿ“‚ scan/ (Scan, Logic, Locks, IPs)' type: boolean default: true run_api: @@ -43,7 +43,7 @@ jobs: run: | PATHS="" # Folder Mapping with 'test/' prefix - if [ "${{ github.event.inputs.run_authoritative }}" == "true" ]; then PATHS="$PATHS test/authoritative_fields/"; fi + if [ "${{ github.event.inputs.scan }}" == "true" ]; then PATHS="$PATHS test/scan/"; fi if [ "${{ github.event.inputs.run_api }}" == "true" ]; then PATHS="$PATHS test/api_endpoints/ test/server/"; fi if [ "${{ github.event.inputs.run_backend }}" == "true" ]; then PATHS="$PATHS test/backend/"; fi if [ "${{ github.event.inputs.run_docker_env }}" == "true" ]; then PATHS="$PATHS test/docker_tests/"; fi diff --git a/test/authoritative_fields/FIELD_LOCK_TEST_SUMMARY.md b/test/scan/FIELD_LOCK_TEST_SUMMARY.md similarity index 100% rename from test/authoritative_fields/FIELD_LOCK_TEST_SUMMARY.md rename to test/scan/FIELD_LOCK_TEST_SUMMARY.md diff --git a/test/authoritative_fields/conftest.py b/test/scan/conftest.py similarity index 74% rename from test/authoritative_fields/conftest.py rename to test/scan/conftest.py index 85f5b6b7..69b8f73c 100644 --- a/test/authoritative_fields/conftest.py +++ b/test/scan/conftest.py @@ -81,6 +81,41 @@ def scan_db(): ) """) + # 3. Events Table + cur.execute(""" + CREATE TABLE Events ( + eve_MAC TEXT, + eve_IP TEXT, + eve_DateTime TEXT, + eve_EventType TEXT, + eve_AdditionalInfo TEXT, + eve_PendingAlertEmail INTEGER + ) + """) + + # 4. LatestEventsPerMAC View + cur.execute("""DROP VIEW IF EXISTS LatestEventsPerMAC;""") + cur.execute(""" + CREATE VIEW LatestEventsPerMAC AS + WITH RankedEvents AS ( + SELECT + e.*, + ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num + FROM Events AS e + ) + SELECT + e.eve_MAC, + e.eve_EventType, + e.eve_DateTime, + e.eve_PendingAlertEmail, + d.devPresentLastScan, + c.scanLastIP + FROM RankedEvents AS e + LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac + LEFT JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac + WHERE e.row_num = 1; + """) + # 3. LatestDeviceScan View (Inner Join for Online Devices) cur.execute(""" CREATE VIEW LatestDeviceScan AS diff --git a/test/authoritative_fields/test_authoritative_handler.py b/test/scan/test_authoritative_handler.py similarity index 100% rename from test/authoritative_fields/test_authoritative_handler.py rename to test/scan/test_authoritative_handler.py diff --git a/test/authoritative_fields/test_device_field_lock.py b/test/scan/test_device_field_lock.py similarity index 100% rename from test/authoritative_fields/test_device_field_lock.py rename to test/scan/test_device_field_lock.py diff --git a/test/authoritative_fields/test_device_status_mappings.py b/test/scan/test_device_status_mappings.py similarity index 100% rename from test/authoritative_fields/test_device_status_mappings.py rename to test/scan/test_device_status_mappings.py diff --git a/test/authoritative_fields/test_field_lock_scan_integration.py b/test/scan/test_field_lock_scan_integration.py similarity index 100% rename from test/authoritative_fields/test_field_lock_scan_integration.py rename to test/scan/test_field_lock_scan_integration.py diff --git a/test/authoritative_fields/test_field_lock_scenarios.py b/test/scan/test_field_lock_scenarios.py similarity index 100% rename from test/authoritative_fields/test_field_lock_scenarios.py rename to test/scan/test_field_lock_scenarios.py diff --git a/test/authoritative_fields/test_force_status.py b/test/scan/test_force_status.py similarity index 100% rename from test/authoritative_fields/test_force_status.py rename to test/scan/test_force_status.py diff --git a/test/authoritative_fields/test_ip_format_and_locking.py b/test/scan/test_ip_format_and_locking.py similarity index 100% rename from test/authoritative_fields/test_ip_format_and_locking.py rename to test/scan/test_ip_format_and_locking.py diff --git a/test/authoritative_fields/test_ip_update_logic.py b/test/scan/test_ip_update_logic.py similarity index 100% rename from test/authoritative_fields/test_ip_update_logic.py rename to test/scan/test_ip_update_logic.py diff --git a/test/server/test_presence_detection.py b/test/scan/test_presence_detection.py similarity index 68% rename from test/server/test_presence_detection.py rename to test/scan/test_presence_detection.py index 88db173e..4f6214aa 100644 --- a/test/server/test_presence_detection.py +++ b/test/scan/test_presence_detection.py @@ -1,86 +1,9 @@ -import sqlite3 from unittest.mock import Mock, patch import pytest from scan.session_events import process_scan -@pytest.fixture -def scan_db(): - conn = sqlite3.connect(":memory:") - conn.row_factory = sqlite3.Row - cur = conn.cursor() - - # Devices - cur.execute(""" - CREATE TABLE Devices ( - devMac TEXT PRIMARY KEY, - devLastIP TEXT, - devPresentLastScan INTEGER, - devAlertDown INTEGER, - devAlertEvents INTEGER, - devIsArchived INTEGER DEFAULT 0 - ) - """) - - # Current scan - cur.execute(""" - CREATE TABLE CurrentScan ( - scanMac TEXT, - scanLastIP TEXT - ) - """) - - # Events - cur.execute(""" - CREATE TABLE Events ( - eve_MAC TEXT, - eve_IP TEXT, - eve_DateTime TEXT, - eve_EventType TEXT, - eve_AdditionalInfo TEXT, - eve_PendingAlertEmail INTEGER - ) - """) - - # LatestEventsPerMAC view - cur.execute("""DROP VIEW IF EXISTS LatestEventsPerMAC;""") - cur.execute(""" - CREATE VIEW LatestEventsPerMAC AS - WITH RankedEvents AS ( - SELECT - e.*, - ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num - FROM Events AS e - ) - SELECT - e.eve_MAC, - e.eve_EventType, - e.eve_DateTime, - e.eve_PendingAlertEmail, - d.devPresentLastScan, - c.scanLastIP - FROM RankedEvents AS e - LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - LEFT JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac - WHERE e.row_num = 1; - """) - - conn.commit() - - db = Mock() - db.sql_connection = conn - db.sql = cur - db.commitDB = conn.commit - - def read(query): - return [dict(cur.execute(query).fetchone())] - - db.read = read - - yield db - conn.close() - @pytest.fixture def minimal_patches():