9740bc64c9
Firmware QEMU Tests (ADR-061) / QEMU Test (edge-tier1) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / QEMU Test (full-adr060) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / QEMU Test (tdm-3node) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / Swarm Test (ADR-062) (push) Has been skipped
npm packages / tools/ruview-mcp (node 22) (push) Failing after 1s
nvsim-server → ghcr.io / build-and-publish (push) Failing after 1s
ruview-swarm CI guard / tests (full+train) (push) Failing after 2s
Bench Regression Guard / bench compile-verify (--no-run) (push) Failing after 0s
Bench Regression Guard / bench fast-run (informational, non-gating) (push) Has been skipped
Firmware CI / Verify version.txt matches release tag (push) Has been skipped
Dashboard a11y + cross-browser / a11y (push) Failing after 0s
nvsim Dashboard → GitHub Pages / build-and-deploy (push) Failing after 2s
Firmware CI / Build firmware (esp32s3 / 4mb) (push) Failing after 15s
Firmware QEMU Tests (ADR-061) / Build Espressif QEMU (push) Failing after 1s
Firmware QEMU Tests (ADR-061) / Fuzz Testing (ADR-061 Layer 6) (push) Failing after 1s
Continuous Deployment / Pre-deployment Checks (push) Has been skipped
Firmware CI / Build firmware (esp32c6 / c6-4mb) (push) Failing after 15s
Firmware CI / Build firmware (esp32s3 / 8mb) (push) Failing after 15s
Firmware QEMU Tests (ADR-061) / QEMU Test (boundary-max) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / QEMU Test (boundary-min) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / QEMU Test (default) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / QEMU Test (edge-tier0) (push) Has been skipped
Firmware QEMU Tests (ADR-061) / NVS Matrix Generation (push) Failing after 1s
Security Scanning / Security Policy Compliance (push) Failing after 0s
Security Scanning / Dependency Vulnerability Scan (push) Failing after 0s
Security Scanning / Static Application Security Testing (push) Failing after 1s
Security Scanning / Infrastructure Security Scan (push) Failing after 1s
Security Scanning / Secret Scanning (push) Failing after 1s
npm packages / harness/ruview (node 22) (push) Failing after 17s
Security Scanning / License Compliance Scan (push) Failing after 1s
Security Scanning / Container Security Scan (push) Failing after 4s
three.js demos → GitHub Pages / build-and-deploy (push) Failing after 1s
Verify Pipeline Determinism / Verify Pipeline Determinism (3.11) (push) Failing after 1s
Fix-Marker Regression Guard / Verify fix markers (push) Failing after 1s
ADR-115 MQTT integration tests / mqtt-integration (push) Failing after 1s
npm packages / harness/ruview (node 20) (push) Failing after 1s
npm packages / tools/ruview-mcp (node 20) (push) Failing after 1s
npm packages / tools/ruview-cli (node 20) (push) Failing after 1s
npm packages / tools/ruview-cli (node 22) (push) Failing after 1s
BFLD MQTT Integration / cargo test --features mqtt (live mosquitto) (push) Failing after 29s
ruview-swarm CI guard / build train_marl bin (push) Failing after 2s
ruview-swarm CI guard / clippy (-D warnings, --no-deps) (push) Failing after 3s
ruview-swarm CI guard / tests (ruflo) (push) Failing after 1s
ruview-swarm CI guard / tests (train) (push) Failing after 2s
ruview-swarm CI guard / tests (default) (push) Failing after 2s
Point Cloud Viewer → GitHub Pages / build-and-deploy (push) Failing after 8s
ruview-swarm CI guard / ITAR / publish guard (push) Failing after 0s
wifi-densepose sensing-server → Docker Hub + ghcr.io / build · push · smoke-test (push) Failing after 1s
Continuous Deployment / Deploy to Production (push) Has been cancelled
Continuous Deployment / Rollback Deployment (push) Has been cancelled
Continuous Deployment / Post-deployment Monitoring (push) Has been cancelled
Continuous Deployment / Notify Deployment Status (push) Has been cancelled
Continuous Deployment / Deploy to Staging (push) Has been cancelled
Security Scanning / Security Report (push) Has been cancelled
244 lines
9.3 KiB
Python
244 lines
9.3 KiB
Python
import pytest
|
|
import numpy as np
|
|
from unittest.mock import Mock, patch, MagicMock
|
|
from src.hardware.router_interface import RouterInterface, RouterConnectionError
|
|
|
|
|
|
class TestRouterInterface:
|
|
"""Test suite for Router Interface following London School TDD principles"""
|
|
|
|
@pytest.fixture
|
|
def mock_config(self):
|
|
"""Configuration for router interface"""
|
|
return {
|
|
'router_ip': '192.168.1.1',
|
|
'username': 'admin',
|
|
'password': 'password',
|
|
'ssh_port': 22,
|
|
'timeout': 30,
|
|
'max_retries': 3
|
|
}
|
|
|
|
@pytest.fixture
|
|
def router_interface(self, mock_config):
|
|
"""Create router interface instance for testing"""
|
|
return RouterInterface(mock_config)
|
|
|
|
@pytest.fixture
|
|
def mock_ssh_client(self):
|
|
"""Mock SSH client for testing"""
|
|
mock_client = Mock()
|
|
mock_client.connect = Mock()
|
|
mock_client.exec_command = Mock()
|
|
mock_client.close = Mock()
|
|
return mock_client
|
|
|
|
def test_interface_initialization_creates_correct_configuration(self, mock_config):
|
|
"""Test that router interface initializes with correct configuration"""
|
|
# Act
|
|
interface = RouterInterface(mock_config)
|
|
|
|
# Assert
|
|
assert interface is not None
|
|
assert interface.router_ip == mock_config['router_ip']
|
|
assert interface.username == mock_config['username']
|
|
assert interface.password == mock_config['password']
|
|
assert interface.ssh_port == mock_config['ssh_port']
|
|
assert interface.timeout == mock_config['timeout']
|
|
assert interface.max_retries == mock_config['max_retries']
|
|
assert not interface.is_connected
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_connect_establishes_ssh_connection(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that connect method establishes SSH connection"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
|
|
# Act
|
|
result = router_interface.connect()
|
|
|
|
# Assert
|
|
assert result is True
|
|
assert router_interface.is_connected is True
|
|
mock_ssh_client.set_missing_host_key_policy.assert_called_once()
|
|
mock_ssh_client.connect.assert_called_once_with(
|
|
hostname=router_interface.router_ip,
|
|
port=router_interface.ssh_port,
|
|
username=router_interface.username,
|
|
password=router_interface.password,
|
|
timeout=router_interface.timeout
|
|
)
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_connect_handles_connection_failure(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that connect method handles connection failures gracefully"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_ssh_client.connect.side_effect = Exception("Connection failed")
|
|
|
|
# Act & Assert
|
|
with pytest.raises(RouterConnectionError):
|
|
router_interface.connect()
|
|
|
|
assert router_interface.is_connected is False
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_disconnect_closes_ssh_connection(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that disconnect method closes SSH connection"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
router_interface.connect()
|
|
|
|
# Act
|
|
router_interface.disconnect()
|
|
|
|
# Assert
|
|
assert router_interface.is_connected is False
|
|
mock_ssh_client.close.assert_called_once()
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_execute_command_runs_ssh_command(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that execute_command runs SSH commands correctly"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_stdout = Mock()
|
|
mock_stdout.read.return_value = b"command output"
|
|
mock_stderr = Mock()
|
|
mock_stderr.read.return_value = b""
|
|
mock_ssh_client.exec_command.return_value = (None, mock_stdout, mock_stderr)
|
|
|
|
router_interface.connect()
|
|
|
|
# Act
|
|
result = router_interface.execute_command("test command")
|
|
|
|
# Assert
|
|
assert result == "command output"
|
|
mock_ssh_client.exec_command.assert_called_with("test command")
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_execute_command_handles_command_errors(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that execute_command handles command errors"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_stdout = Mock()
|
|
mock_stdout.read.return_value = b""
|
|
mock_stderr = Mock()
|
|
mock_stderr.read.return_value = b"command error"
|
|
mock_ssh_client.exec_command.return_value = (None, mock_stdout, mock_stderr)
|
|
|
|
router_interface.connect()
|
|
|
|
# Act & Assert
|
|
with pytest.raises(RouterConnectionError):
|
|
router_interface.execute_command("failing command")
|
|
|
|
def test_execute_command_requires_connection(self, router_interface):
|
|
"""Test that execute_command requires active connection"""
|
|
# Act & Assert
|
|
with pytest.raises(RouterConnectionError):
|
|
router_interface.execute_command("test command")
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_get_router_info_retrieves_system_information(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that get_router_info retrieves router system information"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_stdout = Mock()
|
|
mock_stdout.read.return_value = b"Router Model: AC1900\nFirmware: 1.2.3"
|
|
mock_stderr = Mock()
|
|
mock_stderr.read.return_value = b""
|
|
mock_ssh_client.exec_command.return_value = (None, mock_stdout, mock_stderr)
|
|
|
|
router_interface.connect()
|
|
|
|
# Act
|
|
info = router_interface.get_router_info()
|
|
|
|
# Assert
|
|
assert info is not None
|
|
assert isinstance(info, dict)
|
|
assert 'model' in info
|
|
assert 'firmware' in info
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_enable_monitor_mode_configures_wifi_monitoring(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that enable_monitor_mode configures WiFi monitoring"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_stdout = Mock()
|
|
mock_stdout.read.return_value = b"Monitor mode enabled"
|
|
mock_stderr = Mock()
|
|
mock_stderr.read.return_value = b""
|
|
mock_ssh_client.exec_command.return_value = (None, mock_stdout, mock_stderr)
|
|
|
|
router_interface.connect()
|
|
|
|
# Act
|
|
result = router_interface.enable_monitor_mode("wlan0")
|
|
|
|
# Assert
|
|
assert result is True
|
|
mock_ssh_client.exec_command.assert_called()
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_disable_monitor_mode_disables_wifi_monitoring(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that disable_monitor_mode disables WiFi monitoring"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_stdout = Mock()
|
|
mock_stdout.read.return_value = b"Monitor mode disabled"
|
|
mock_stderr = Mock()
|
|
mock_stderr.read.return_value = b""
|
|
mock_ssh_client.exec_command.return_value = (None, mock_stdout, mock_stderr)
|
|
|
|
router_interface.connect()
|
|
|
|
# Act
|
|
result = router_interface.disable_monitor_mode("wlan0")
|
|
|
|
# Assert
|
|
assert result is True
|
|
mock_ssh_client.exec_command.assert_called()
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_interface_supports_context_manager(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that router interface supports context manager protocol"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
|
|
# Act
|
|
with router_interface as interface:
|
|
# Assert
|
|
assert interface.is_connected is True
|
|
|
|
# Assert - connection should be closed after context
|
|
assert router_interface.is_connected is False
|
|
mock_ssh_client.close.assert_called_once()
|
|
|
|
def test_interface_validates_configuration(self):
|
|
"""Test that router interface validates configuration parameters"""
|
|
# Arrange
|
|
invalid_config = {
|
|
'router_ip': '', # Invalid IP
|
|
'username': 'admin',
|
|
'password': 'password'
|
|
}
|
|
|
|
# Act & Assert
|
|
with pytest.raises(ValueError):
|
|
RouterInterface(invalid_config)
|
|
|
|
@patch('paramiko.SSHClient')
|
|
def test_interface_implements_retry_logic(self, mock_ssh_class, router_interface, mock_ssh_client):
|
|
"""Test that interface implements retry logic for failed operations"""
|
|
# Arrange
|
|
mock_ssh_class.return_value = mock_ssh_client
|
|
mock_ssh_client.connect.side_effect = [Exception("Temp failure"), None] # Fail once, then succeed
|
|
|
|
# Act
|
|
result = router_interface.connect()
|
|
|
|
# Assert
|
|
assert result is True
|
|
assert mock_ssh_client.connect.call_count == 2 # Should retry once |