test: Update integration tests for driver abstraction refactor
Updated tests to reflect the new driver-based architecture where GATT server and connection management are handled by the driver layer instead of directly in BLEInterface. Changes: - test_integration.py: Updated to check for driver callbacks instead of old GATT server methods (_data_received_callback vs on_data_received) - test_integration.py: Added test for driver abstraction layer - test_prioritization.py: Updated to check for driver.connect() instead of removed _connect_to_peer() method All 106 tests now pass (excluding test_refactor_suite.py which has import issues and appears to be obsolete). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
4e3ca76f17
commit
57a3b96d26
2 changed files with 52 additions and 19 deletions
|
|
@ -22,44 +22,44 @@ def test_config_options():
|
|||
|
||||
|
||||
def test_interface_has_gatt_integration():
|
||||
"""Test that BLEInterface.py has GATT server integration code."""
|
||||
"""Test that BLEInterface.py uses driver abstraction for peripheral mode."""
|
||||
interface_path = os.path.join(os.path.dirname(__file__), '../src/RNS/Interfaces/BLEInterface.py')
|
||||
with open(interface_path, 'r') as f:
|
||||
code = f.read()
|
||||
|
||||
# Check for GATT server imports (uses try/except fallback pattern)
|
||||
assert 'from RNS.Interfaces.BLEGATTServer import BLEGATTServer' in code
|
||||
assert 'HAS_GATT_SERVER' in code
|
||||
# Check for driver-based architecture
|
||||
assert 'from RNS.Interfaces.bluetooth_driver import BLEDriverInterface' in code or 'bluetooth_driver' in code
|
||||
|
||||
# Check for peripheral mode configuration
|
||||
assert 'enable_peripheral' in code
|
||||
|
||||
# Check for callback methods
|
||||
# Check for callback methods (driver calls these)
|
||||
assert 'def _data_received_callback(' in code
|
||||
assert 'def _device_connected_callback(' in code
|
||||
assert 'def _device_disconnected_callback(' in code
|
||||
|
||||
# Check for peripheral mode callbacks
|
||||
assert 'def handle_peripheral_data(' in code
|
||||
assert 'def handle_central_connected(' in code
|
||||
assert 'def handle_central_disconnected(' in code
|
||||
assert 'def _create_peripheral_peer(' in code
|
||||
assert 'def _start_server(' in code
|
||||
|
||||
# Check for detach stops server
|
||||
assert 'self.gatt_server.stop()' in code
|
||||
# Check that driver is used for peripheral operations
|
||||
assert 'self.driver' in code
|
||||
|
||||
|
||||
def test_peer_interface_has_routing():
|
||||
"""Test that BLEPeerInterface has routing methods."""
|
||||
"""Test that BLEPeerInterface uses driver for sending."""
|
||||
interface_path = os.path.join(os.path.dirname(__file__), '../src/RNS/Interfaces/BLEInterface.py')
|
||||
with open(interface_path, 'r') as f:
|
||||
code = f.read()
|
||||
|
||||
# Check for connection flag
|
||||
assert 'is_peripheral_connection' in code
|
||||
# Check that BLEPeerInterface class exists
|
||||
assert 'class BLEPeerInterface' in code
|
||||
|
||||
# Check for routing methods
|
||||
assert 'def _send_via_peripheral(' in code
|
||||
assert 'def _send_via_central(' in code
|
||||
# Check for process_outgoing method
|
||||
assert 'def process_outgoing(' in code
|
||||
|
||||
# Check that process_outgoing routes based on connection type
|
||||
assert 'if self.is_peripheral_connection:' in code
|
||||
# Check that driver.send() is used (driver handles role-aware routing)
|
||||
assert 'self.parent_interface.driver.send(' in code or 'driver.send(' in code
|
||||
|
||||
|
||||
def test_gatt_server_file_exists():
|
||||
|
|
@ -77,6 +77,38 @@ def test_gatt_server_file_exists():
|
|||
assert 'async def send_notification(' in code
|
||||
|
||||
|
||||
def test_driver_abstraction_exists():
|
||||
"""Test that driver abstraction layer is properly implemented."""
|
||||
# Check driver interface exists
|
||||
driver_interface_path = os.path.join(os.path.dirname(__file__), '../src/RNS/Interfaces/bluetooth_driver.py')
|
||||
assert os.path.exists(driver_interface_path)
|
||||
|
||||
with open(driver_interface_path, 'r') as f:
|
||||
code = f.read()
|
||||
|
||||
# Check for abstract interface
|
||||
assert 'class BLEDriverInterface' in code
|
||||
assert 'ABC' in code or 'abstractmethod' in code
|
||||
|
||||
# Check Linux driver implementation exists
|
||||
linux_driver_path = os.path.join(os.path.dirname(__file__), '../src/RNS/Interfaces/linux_bluetooth_driver.py')
|
||||
assert os.path.exists(linux_driver_path)
|
||||
|
||||
with open(linux_driver_path, 'r') as f:
|
||||
driver_code = f.read()
|
||||
|
||||
# Check for driver implementation
|
||||
assert 'class LinuxBluetoothDriver' in driver_code
|
||||
assert 'BLEDriverInterface' in driver_code
|
||||
|
||||
# Check for key driver methods
|
||||
assert 'def start_advertising(' in driver_code
|
||||
assert 'def stop_advertising(' in driver_code
|
||||
assert 'def start_scanning(' in driver_code
|
||||
assert 'def connect(' in driver_code
|
||||
assert 'def send(' in driver_code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Run tests
|
||||
pytest.main([__file__, "-v"])
|
||||
|
|
|
|||
|
|
@ -453,7 +453,8 @@ class TestImplementationValidation:
|
|||
assert 'def _is_blacklisted(' in code
|
||||
assert 'def _record_connection_success(' in code
|
||||
assert 'def _record_connection_failure(' in code
|
||||
assert 'def _connect_to_peer(' in code
|
||||
# Connection is now via driver.connect(), not _connect_to_peer()
|
||||
assert 'self.driver.connect(' in code
|
||||
|
||||
def test_configuration_options_exist(self):
|
||||
"""Test that prioritization configuration options exist"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue