Lemontropia-Suite/tests/test_gui_integration.py

131 lines
4.4 KiB
Python

"""
Tests for GUI integration with core modules.
Verifies MainWindow properly integrates with ProjectManager, LogWatcher, etc.
"""
import pytest
import sys
from pathlib import Path
from unittest.mock import Mock, MagicMock, patch
# Add project to path
sys.path.insert(0, str(Path(__file__).parent.parent))
class TestProjectDataCompatibility:
"""Test that GUI uses correct ProjectData attributes."""
def test_project_data_has_required_fields(self):
"""Verify ProjectData has fields used by GUI."""
from core.project_manager import ProjectData
project = ProjectData(
id=1,
name="Test Project",
type="hunt",
status="active"
)
# Fields used by GUI
assert hasattr(project, 'id')
assert hasattr(project, 'name')
assert hasattr(project, 'type')
assert hasattr(project, 'status')
# Fields NOT in ProjectData (GUI was incorrectly using these)
assert not hasattr(project, 'session_count')
assert not hasattr(project, 'description')
def test_project_manager_methods_exist(self):
"""Verify ProjectManager has methods called by GUI."""
from core.project_manager import ProjectManager
pm = ProjectManager()
# Methods GUI uses
assert hasattr(pm, 'list_projects')
assert hasattr(pm, 'load_project')
assert hasattr(pm, 'create_project')
assert hasattr(pm, 'start_session')
assert hasattr(pm, 'end_session')
assert hasattr(pm, 'record_loot')
# Methods GUI should NOT call (old placeholder names)
assert not hasattr(pm, 'get_all_projects')
assert not hasattr(pm, 'get_project')
class TestLogWatcherCompatibility:
"""Test LogWatcher integration."""
def test_log_watcher_has_subscribe(self):
"""Verify LogWatcher has subscribe method."""
from core.log_watcher import LogWatcher
# Can't instantiate without file, but can check class
assert hasattr(LogWatcher, 'subscribe')
assert hasattr(LogWatcher, 'start')
assert hasattr(LogWatcher, 'stop')
class TestMainWindowIntegration:
"""Test MainWindow integration with core modules."""
@pytest.fixture
def mock_qapp(self):
"""Create mock QApplication."""
with patch('PyQt6.QtWidgets.QApplication') as mock_app:
mock_instance = Mock()
mock_app.instance.return_value = mock_instance
yield mock_instance
def test_main_window_imports(self, mock_qapp):
"""Test MainWindow can import without errors."""
with patch('ui.main_window.DatabaseManager') as mock_db, \
patch('ui.main_window.ProjectManager') as mock_pm, \
patch('ui.main_window.HUDOverlay'), \
patch('ui.main_window.QMainWindow'):
mock_db_instance = Mock()
mock_db_instance.initialize.return_value = True
mock_db.return_value = mock_db_instance
mock_pm_instance = Mock()
mock_pm_instance.list_projects.return_value = []
mock_pm.return_value = mock_pm_instance
from ui.main_window import MainWindow
# Should not raise ImportError or AttributeError
class TestProjectManagerMethodSignatures:
"""Test ProjectManager method signatures match GUI expectations."""
def test_create_project_signature(self):
"""Test create_project accepts correct arguments."""
from core.project_manager import ProjectManager
import inspect
sig = inspect.signature(ProjectManager.create_project)
params = list(sig.parameters.keys())
# Should have: self, name, project_type, description=""
assert 'name' in params
assert 'project_type' in params
assert 'description' in params
def test_list_projects_signature(self):
"""Test list_projects has correct signature."""
from core.project_manager import ProjectManager
import inspect
sig = inspect.signature(ProjectManager.list_projects)
params = list(sig.parameters.keys())
# Should have optional filters
assert 'project_type' in params
assert 'status' in params
if __name__ == "__main__":
pytest.main([__file__, "-v"])