new folder structure

This commit is contained in:
2025-09-29 09:17:13 +02:00
parent 38117ab875
commit 78fc6068fb
197 changed files with 3490 additions and 1117 deletions

View File

@@ -0,0 +1 @@
# Test package initialization

View File

@@ -0,0 +1,20 @@
@echo off
echo.
echo 🚀 AniWorld Core Functionality Tests
echo =====================================
echo.
cd /d "%~dp0"
python run_core_tests.py
if %ERRORLEVEL% EQU 0 (
echo.
echo ✅ All tests completed successfully!
) else (
echo.
echo ❌ Some tests failed. Check output above.
)
echo.
echo Press any key to continue...
pause > nul

View File

@@ -0,0 +1,57 @@
"""
Simple test runner for core AniWorld server functionality.
This script runs the essential tests to validate JavaScript/CSS generation.
"""
import unittest
import sys
import os
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if __name__ == '__main__':
print("🚀 Running AniWorld Core Functionality Tests")
print("=" * 50)
# Import and run the core tests
from test_core_functionality import TestManagerGenerationCore, TestComprehensiveSuite
# Create test suite
suite = unittest.TestSuite()
# Add core manager tests
suite.addTest(TestManagerGenerationCore('test_keyboard_shortcut_manager_generation'))
suite.addTest(TestManagerGenerationCore('test_drag_drop_manager_generation'))
suite.addTest(TestManagerGenerationCore('test_accessibility_manager_generation'))
suite.addTest(TestManagerGenerationCore('test_user_preferences_manager_generation'))
suite.addTest(TestManagerGenerationCore('test_advanced_search_manager_generation'))
suite.addTest(TestManagerGenerationCore('test_undo_redo_manager_generation'))
suite.addTest(TestManagerGenerationCore('test_multi_screen_manager_generation'))
# Add comprehensive test
suite.addTest(TestComprehensiveSuite('test_all_manager_fixes_comprehensive'))
# Run tests
runner = unittest.TextTestRunner(verbosity=1, buffer=True)
result = runner.run(suite)
# Print summary
print("\n" + "=" * 50)
if result.wasSuccessful():
print("🎉 ALL CORE TESTS PASSED!")
print("✅ JavaScript/CSS generation working correctly")
print("✅ All manager classes validated")
print("✅ No syntax or runtime errors found")
else:
print("❌ Some core tests failed")
if result.failures:
for test, error in result.failures:
print(f" FAIL: {test}")
if result.errors:
for test, error in result.errors:
print(f" ERROR: {test}")
print("=" * 50)
sys.exit(0 if result.wasSuccessful() else 1)

View File

@@ -0,0 +1,10 @@
@echo off
echo Running AniWorld Server Test Suite...
echo.
cd /d "%~dp0"
python run_tests.py
echo.
echo Test run completed.
pause

108
tests/unit/web/run_tests.py Normal file
View File

@@ -0,0 +1,108 @@
"""
Test runner for the AniWorld server test suite.
This script runs all test modules and provides a comprehensive report.
"""
import unittest
import sys
import os
from io import StringIO
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def run_all_tests():
"""Run all test modules and provide a summary report."""
print("=" * 60)
print("AniWorld Server Test Suite")
print("=" * 60)
# Discover and run all tests
loader = unittest.TestLoader()
test_dir = os.path.dirname(os.path.abspath(__file__))
# Load all test modules
suite = loader.discover(test_dir, pattern='test_*.py')
# Run tests with detailed output
stream = StringIO()
runner = unittest.TextTestRunner(
stream=stream,
verbosity=2,
buffer=True
)
result = runner.run(suite)
# Print results
output = stream.getvalue()
print(output)
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
total_tests = result.testsRun
failures = len(result.failures)
errors = len(result.errors)
skipped = len(result.skipped) if hasattr(result, 'skipped') else 0
passed = total_tests - failures - errors - skipped
print(f"Total Tests Run: {total_tests}")
print(f"Passed: {passed}")
print(f"Failed: {failures}")
print(f"Errors: {errors}")
print(f"Skipped: {skipped}")
if result.wasSuccessful():
print("\n🎉 ALL TESTS PASSED! 🎉")
print("✅ No JavaScript or CSS generation issues found!")
print("✅ All manager classes working correctly!")
print("✅ Authentication system validated!")
return True
else:
print("\n❌ Some tests failed. Please check the output above.")
if result.failures:
print(f"\nFailures ({len(result.failures)}):")
for test, traceback in result.failures:
print(f" - {test}: {traceback.split(chr(10))[-2]}")
if result.errors:
print(f"\nErrors ({len(result.errors)}):")
for test, traceback in result.errors:
print(f" - {test}: {traceback.split(chr(10))[-2]}")
return False
def run_specific_test_module(module_name):
"""Run a specific test module."""
print(f"Running tests from module: {module_name}")
print("-" * 40)
loader = unittest.TestLoader()
suite = loader.loadTestsFromName(module_name)
runner = unittest.TextTestRunner(verbosity=2, buffer=True)
result = runner.run(suite)
return result.wasSuccessful()
if __name__ == '__main__':
if len(sys.argv) > 1:
# Run specific test module
module_name = sys.argv[1]
success = run_specific_test_module(module_name)
else:
# Run all tests
success = run_all_tests()
# Exit with appropriate code
sys.exit(0 if success else 1)

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""
Test script to verify Flask app structure without initializing SeriesApp
"""
import sys
import os
# Test if we can import Flask modules
try:
from flask import Flask
from flask_socketio import SocketIO
print("✅ Flask and SocketIO imports successful")
except ImportError as e:
print(f"❌ Flask import failed: {e}")
sys.exit(1)
# Test if we can import our modules
try:
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
from src.server.core.entities.series import Serie
from src.server.core.entities.SerieList import SerieList
print("✅ Core modules import successful")
except ImportError as e:
print(f"❌ Core module import failed: {e}")
sys.exit(1)
# Test Flask app creation
try:
app = Flask(__name__)
app.config['SECRET_KEY'] = 'test-key'
socketio = SocketIO(app, cors_allowed_origins="*")
print("✅ Flask app creation successful")
except Exception as e:
print(f"❌ Flask app creation failed: {e}")
sys.exit(1)
print("🎉 All tests passed! Flask app structure is valid.")
print("\nTo run the server:")
print("1. Set ANIME_DIRECTORY environment variable to your anime directory")
print("2. Run: python app.py")
print("3. Open browser to http://localhost:5000")

View File

@@ -0,0 +1,127 @@
"""
Test suite for authentication and session management.
This test module validates the authentication system, session management,
and security features.
"""
import unittest
import sys
import os
from unittest.mock import patch, MagicMock
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
class TestAuthenticationSystem(unittest.TestCase):
"""Test class for authentication and session management."""
def setUp(self):
"""Set up test fixtures before each test method."""
# Mock Flask app for testing
self.mock_app = MagicMock()
self.mock_app.config = {'SECRET_KEY': 'test_secret'}
def test_session_manager_initialization(self):
"""Test SessionManager initialization."""
try:
from auth import SessionManager
manager = SessionManager()
self.assertIsNotNone(manager)
self.assertTrue(hasattr(manager, 'login'))
self.assertTrue(hasattr(manager, 'check_password'))
print('✓ SessionManager initialization successful')
except Exception as e:
self.fail(f'SessionManager initialization failed: {e}')
def test_login_method_exists(self):
"""Test that login method exists and returns proper response."""
try:
from auth import SessionManager
manager = SessionManager()
# Test login method exists
self.assertTrue(hasattr(manager, 'login'))
# Test login with invalid credentials returns dict
result = manager.login('wrong_password')
self.assertIsInstance(result, dict)
self.assertIn('success', result)
self.assertFalse(result['success'])
print('✓ SessionManager login method validated')
except Exception as e:
self.fail(f'SessionManager login method test failed: {e}')
def test_password_checking(self):
"""Test password validation functionality."""
try:
from auth import SessionManager
manager = SessionManager()
# Test check_password method exists
self.assertTrue(hasattr(manager, 'check_password'))
# Test with empty/invalid password
result = manager.check_password('')
self.assertFalse(result)
result = manager.check_password('wrong_password')
self.assertFalse(result)
print('✓ SessionManager password checking validated')
except Exception as e:
self.fail(f'SessionManager password checking test failed: {e}')
class TestConfigurationSystem(unittest.TestCase):
"""Test class for configuration management."""
def test_config_manager_initialization(self):
"""Test ConfigManager initialization."""
try:
from config import ConfigManager
manager = ConfigManager()
self.assertIsNotNone(manager)
self.assertTrue(hasattr(manager, 'anime_directory'))
print('✓ ConfigManager initialization successful')
except Exception as e:
self.fail(f'ConfigManager initialization failed: {e}')
def test_anime_directory_property(self):
"""Test anime_directory property getter and setter."""
try:
from config import ConfigManager
manager = ConfigManager()
# Test getter
initial_dir = manager.anime_directory
self.assertIsInstance(initial_dir, str)
# Test setter exists
test_dir = 'C:\\TestAnimeDir'
manager.anime_directory = test_dir
# Verify setter worked
self.assertEqual(manager.anime_directory, test_dir)
print('✓ ConfigManager anime_directory property validated')
except Exception as e:
self.fail(f'ConfigManager anime_directory property test failed: {e}')
if __name__ == '__main__':
unittest.main(verbosity=2, buffer=True)

View File

@@ -0,0 +1,288 @@
"""
Focused test suite for manager JavaScript and CSS generation.
This test module validates the core functionality that we know is working.
"""
import unittest
import sys
import os
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
class TestManagerGenerationCore(unittest.TestCase):
"""Test class for validating core manager JavaScript/CSS generation functionality."""
def setUp(self):
"""Set up test fixtures before each test method."""
self.managers_tested = 0
self.total_js_chars = 0
self.total_css_chars = 0
print("\n" + "="*50)
def test_keyboard_shortcut_manager_generation(self):
"""Test KeyboardShortcutManager JavaScript generation."""
print("Testing KeyboardShortcutManager...")
try:
from keyboard_shortcuts import KeyboardShortcutManager
manager = KeyboardShortcutManager()
js = manager.get_shortcuts_js()
# Validate JS generation
self.assertIsInstance(js, str)
self.assertGreater(len(js), 1000) # Should be substantial
self.total_js_chars += len(js)
self.managers_tested += 1
print(f'✓ KeyboardShortcutManager: {len(js):,} JS characters generated')
except Exception as e:
self.fail(f'KeyboardShortcutManager test failed: {e}')
def test_drag_drop_manager_generation(self):
"""Test DragDropManager JavaScript and CSS generation."""
print("Testing DragDropManager...")
try:
from drag_drop import DragDropManager
manager = DragDropManager()
js = manager.get_drag_drop_js()
css = manager.get_css()
# Validate generation
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 1000)
self.assertGreater(len(css), 100)
# Check for proper JSON serialization (no Python booleans)
self.assertNotIn('True', js)
self.assertNotIn('False', js)
self.assertNotIn('None', js)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ DragDropManager: {len(js):,} JS chars, {len(css):,} CSS chars')
except Exception as e:
self.fail(f'DragDropManager test failed: {e}')
def test_accessibility_manager_generation(self):
"""Test AccessibilityManager JavaScript and CSS generation."""
print("Testing AccessibilityManager...")
try:
from accessibility_features import AccessibilityManager
manager = AccessibilityManager()
js = manager.get_accessibility_js()
css = manager.get_css()
# Validate generation
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 1000)
self.assertGreater(len(css), 100)
# Check for proper JSON serialization
self.assertNotIn('True', js)
self.assertNotIn('False', js)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ AccessibilityManager: {len(js):,} JS chars, {len(css):,} CSS chars')
except Exception as e:
self.fail(f'AccessibilityManager test failed: {e}')
def test_user_preferences_manager_generation(self):
"""Test UserPreferencesManager JavaScript and CSS generation."""
print("Testing UserPreferencesManager...")
try:
from user_preferences import UserPreferencesManager
manager = UserPreferencesManager()
# Verify preferences attribute exists (this was the main fix)
self.assertTrue(hasattr(manager, 'preferences'))
self.assertIsInstance(manager.preferences, dict)
js = manager.get_preferences_js()
css = manager.get_css()
# Validate generation
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 1000)
self.assertGreater(len(css), 100)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ UserPreferencesManager: {len(js):,} JS chars, {len(css):,} CSS chars')
except Exception as e:
self.fail(f'UserPreferencesManager test failed: {e}')
def test_advanced_search_manager_generation(self):
"""Test AdvancedSearchManager JavaScript and CSS generation."""
print("Testing AdvancedSearchManager...")
try:
from advanced_search import AdvancedSearchManager
manager = AdvancedSearchManager()
js = manager.get_search_js()
css = manager.get_css()
# Validate generation
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 1000)
self.assertGreater(len(css), 100)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ AdvancedSearchManager: {len(js):,} JS chars, {len(css):,} CSS chars')
except Exception as e:
self.fail(f'AdvancedSearchManager test failed: {e}')
def test_undo_redo_manager_generation(self):
"""Test UndoRedoManager JavaScript and CSS generation."""
print("Testing UndoRedoManager...")
try:
from undo_redo_manager import UndoRedoManager
manager = UndoRedoManager()
js = manager.get_undo_redo_js()
css = manager.get_css()
# Validate generation
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 1000)
self.assertGreater(len(css), 100)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ UndoRedoManager: {len(js):,} JS chars, {len(css):,} CSS chars')
except Exception as e:
self.fail(f'UndoRedoManager test failed: {e}')
def test_multi_screen_manager_generation(self):
"""Test MultiScreenManager JavaScript and CSS generation."""
print("Testing MultiScreenManager...")
try:
from multi_screen_support import MultiScreenManager
manager = MultiScreenManager()
js = manager.get_multiscreen_js()
css = manager.get_multiscreen_css()
# Validate generation
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 1000)
self.assertGreater(len(css), 100)
# Check for proper f-string escaping (no Python syntax)
self.assertNotIn('True', js)
self.assertNotIn('False', js)
self.assertNotIn('None', js)
# Verify JavaScript is properly formatted
self.assertIn('class', js) # Should contain JavaScript class syntax
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ MultiScreenManager: {len(js):,} JS chars, {len(css):,} CSS chars')
except Exception as e:
self.fail(f'MultiScreenManager test failed: {e}')
class TestComprehensiveSuite(unittest.TestCase):
"""Comprehensive test to verify all fixes are working."""
def test_all_manager_fixes_comprehensive(self):
"""Run comprehensive test of all manager fixes."""
print("\n" + "="*60)
print("COMPREHENSIVE MANAGER VALIDATION")
print("="*60)
managers_tested = 0
total_js = 0
total_css = 0
# Test each manager
test_cases = [
('KeyboardShortcutManager', 'keyboard_shortcuts', 'get_shortcuts_js', None),
('DragDropManager', 'drag_drop', 'get_drag_drop_js', 'get_css'),
('AccessibilityManager', 'accessibility_features', 'get_accessibility_js', 'get_css'),
('UserPreferencesManager', 'user_preferences', 'get_preferences_js', 'get_css'),
('AdvancedSearchManager', 'advanced_search', 'get_search_js', 'get_css'),
('UndoRedoManager', 'undo_redo_manager', 'get_undo_redo_js', 'get_css'),
('MultiScreenManager', 'multi_screen_support', 'get_multiscreen_js', 'get_multiscreen_css'),
]
for class_name, module_name, js_method, css_method in test_cases:
try:
# Dynamic import
module = __import__(module_name, fromlist=[class_name])
manager_class = getattr(module, class_name)
manager = manager_class()
# Get JS
js_func = getattr(manager, js_method)
js = js_func()
self.assertIsInstance(js, str)
self.assertGreater(len(js), 0)
total_js += len(js)
# Get CSS if available
css_chars = 0
if css_method:
css_func = getattr(manager, css_method)
css = css_func()
self.assertIsInstance(css, str)
self.assertGreater(len(css), 0)
css_chars = len(css)
total_css += css_chars
managers_tested += 1
print(f'{class_name}: JS={len(js):,} chars' +
(f', CSS={css_chars:,} chars' if css_chars > 0 else ' (JS only)'))
except Exception as e:
self.fail(f'{class_name} failed: {e}')
# Final validation
expected_managers = 7
self.assertEqual(managers_tested, expected_managers)
self.assertGreater(total_js, 100000) # Should have substantial JS
self.assertGreater(total_css, 10000) # Should have substantial CSS
print(f'\n{"="*60}')
print(f'🎉 ALL {managers_tested} MANAGERS PASSED!')
print(f'📊 Total JavaScript: {total_js:,} characters')
print(f'🎨 Total CSS: {total_css:,} characters')
print(f'✅ No JavaScript or CSS generation issues found!')
print(f'{"="*60}')
if __name__ == '__main__':
# Run with high verbosity
unittest.main(verbosity=2, buffer=False)

View File

@@ -0,0 +1,131 @@
"""
Test suite for Flask application routes and API endpoints.
This test module validates the main Flask application functionality,
route handling, and API responses.
"""
import unittest
import sys
import os
from unittest.mock import patch, MagicMock
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
class TestFlaskApplication(unittest.TestCase):
"""Test class for Flask application and routes."""
def setUp(self):
"""Set up test fixtures before each test method."""
pass
def test_app_imports(self):
"""Test that main app module can be imported without errors."""
try:
import app
self.assertIsNotNone(app)
print('✓ Main app module imports successfully')
except Exception as e:
self.fail(f'App import failed: {e}')
@patch('app.Flask')
def test_app_initialization_components(self, mock_flask):
"""Test that app initialization components are available."""
try:
# Test manager imports
from keyboard_shortcuts import KeyboardShortcutManager
from drag_drop import DragDropManager
from accessibility_features import AccessibilityManager
from user_preferences import UserPreferencesManager
# Verify managers can be instantiated
keyboard_manager = KeyboardShortcutManager()
drag_manager = DragDropManager()
accessibility_manager = AccessibilityManager()
preferences_manager = UserPreferencesManager()
self.assertIsNotNone(keyboard_manager)
self.assertIsNotNone(drag_manager)
self.assertIsNotNone(accessibility_manager)
self.assertIsNotNone(preferences_manager)
print('✓ App manager components available')
except Exception as e:
self.fail(f'App component test failed: {e}')
class TestAPIEndpoints(unittest.TestCase):
"""Test class for API endpoint validation."""
def test_api_response_structure(self):
"""Test that API endpoints return proper JSON structure."""
try:
# Test that we can import the auth module for API responses
from auth import SessionManager
manager = SessionManager()
# Test login API response structure
response = manager.login('test_password')
self.assertIsInstance(response, dict)
self.assertIn('success', response)
print('✓ API response structure validated')
except Exception as e:
self.fail(f'API endpoint test failed: {e}')
class TestJavaScriptGeneration(unittest.TestCase):
"""Test class for dynamic JavaScript generation."""
def test_javascript_generation_no_syntax_errors(self):
"""Test that generated JavaScript doesn't contain Python syntax."""
try:
from multi_screen_support import MultiScreenSupportManager
manager = MultiScreenSupportManager()
js_code = manager.get_multiscreen_js()
# Check for Python-specific syntax that shouldn't be in JS
self.assertNotIn('True', js_code, 'JavaScript should use "true", not "True"')
self.assertNotIn('False', js_code, 'JavaScript should use "false", not "False"')
self.assertNotIn('None', js_code, 'JavaScript should use "null", not "None"')
# Check for proper JSON serialization indicators
self.assertIn('true', js_code.lower())
self.assertIn('false', js_code.lower())
print('✓ JavaScript generation syntax validated')
except Exception as e:
self.fail(f'JavaScript generation test failed: {e}')
def test_f_string_escaping(self):
"""Test that f-strings are properly escaped in JavaScript generation."""
try:
from multi_screen_support import MultiScreenSupportManager
manager = MultiScreenSupportManager()
js_code = manager.get_multiscreen_js()
# Ensure JavaScript object literals use proper syntax
# Look for proper JavaScript object/function syntax
self.assertGreater(len(js_code), 0)
# Check that braces are properly used (not bare Python f-string braces)
brace_count = js_code.count('{')
self.assertGreater(brace_count, 0)
print('✓ F-string escaping validated')
except Exception as e:
self.fail(f'F-string escaping test failed: {e}')
if __name__ == '__main__':
unittest.main(verbosity=2, buffer=True)

View File

@@ -0,0 +1,242 @@
"""
Test suite for manager JavaScript and CSS generation.
This test module validates that all manager classes can successfully generate
their JavaScript and CSS code without runtime errors.
"""
import unittest
import sys
import os
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
class TestManagerGeneration(unittest.TestCase):
"""Test class for validating manager JavaScript/CSS generation."""
def setUp(self):
"""Set up test fixtures before each test method."""
self.managers_tested = 0
self.total_js_chars = 0
self.total_css_chars = 0
def test_keyboard_shortcut_manager(self):
"""Test KeyboardShortcutManager JavaScript generation."""
try:
from keyboard_shortcuts import KeyboardShortcutManager
manager = KeyboardShortcutManager()
js = manager.get_shortcuts_js()
self.assertIsInstance(js, str)
self.assertGreater(len(js), 0)
self.total_js_chars += len(js)
self.managers_tested += 1
print(f'✓ KeyboardShortcutManager: JS={len(js)} chars (no CSS method)')
except Exception as e:
self.fail(f'KeyboardShortcutManager failed: {e}')
def test_drag_drop_manager(self):
"""Test DragDropManager JavaScript and CSS generation."""
try:
from drag_drop import DragDropManager
manager = DragDropManager()
js = manager.get_drag_drop_js()
css = manager.get_css()
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 0)
self.assertGreater(len(css), 0)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ DragDropManager: JS={len(js)} chars, CSS={len(css)} chars')
except Exception as e:
self.fail(f'DragDropManager failed: {e}')
def test_accessibility_manager(self):
"""Test AccessibilityManager JavaScript and CSS generation."""
try:
from accessibility_features import AccessibilityManager
manager = AccessibilityManager()
js = manager.get_accessibility_js()
css = manager.get_css()
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 0)
self.assertGreater(len(css), 0)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ AccessibilityManager: JS={len(js)} chars, CSS={len(css)} chars')
except Exception as e:
self.fail(f'AccessibilityManager failed: {e}')
def test_user_preferences_manager(self):
"""Test UserPreferencesManager JavaScript and CSS generation."""
try:
from user_preferences import UserPreferencesManager
manager = UserPreferencesManager()
js = manager.get_preferences_js()
css = manager.get_css()
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 0)
self.assertGreater(len(css), 0)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ UserPreferencesManager: JS={len(js)} chars, CSS={len(css)} chars')
except Exception as e:
self.fail(f'UserPreferencesManager failed: {e}')
def test_advanced_search_manager(self):
"""Test AdvancedSearchManager JavaScript and CSS generation."""
try:
from advanced_search import AdvancedSearchManager
manager = AdvancedSearchManager()
js = manager.get_search_js()
css = manager.get_css()
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 0)
self.assertGreater(len(css), 0)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ AdvancedSearchManager: JS={len(js)} chars, CSS={len(css)} chars')
except Exception as e:
self.fail(f'AdvancedSearchManager failed: {e}')
def test_undo_redo_manager(self):
"""Test UndoRedoManager JavaScript and CSS generation."""
try:
from undo_redo_manager import UndoRedoManager
manager = UndoRedoManager()
js = manager.get_undo_redo_js()
css = manager.get_css()
self.assertIsInstance(js, str)
self.assertIsInstance(css, str)
self.assertGreater(len(js), 0)
self.assertGreater(len(css), 0)
self.total_js_chars += len(js)
self.total_css_chars += len(css)
self.managers_tested += 1
print(f'✓ UndoRedoManager: JS={len(js)} chars, CSS={len(css)} chars')
except Exception as e:
self.fail(f'UndoRedoManager failed: {e}')
def test_all_managers_comprehensive(self):
"""Comprehensive test to ensure all managers work together."""
expected_managers = 6 # Total number of managers we expect to test
# Run all individual tests first
self.test_keyboard_shortcut_manager()
self.test_drag_drop_manager()
self.test_accessibility_manager()
self.test_user_preferences_manager()
self.test_advanced_search_manager()
self.test_undo_redo_manager()
# Validate overall results
self.assertEqual(self.managers_tested, expected_managers)
self.assertGreater(self.total_js_chars, 0)
self.assertGreater(self.total_css_chars, 0)
print(f'\n=== COMPREHENSIVE TEST SUMMARY ===')
print(f'Managers tested: {self.managers_tested}/{expected_managers}')
print(f'Total JavaScript generated: {self.total_js_chars:,} characters')
print(f'Total CSS generated: {self.total_css_chars:,} characters')
print('🎉 All manager JavaScript/CSS generation tests passed!')
def tearDown(self):
"""Clean up after each test method."""
pass
class TestManagerMethods(unittest.TestCase):
"""Test class for validating specific manager methods."""
def test_keyboard_shortcuts_methods(self):
"""Test that KeyboardShortcutManager has required methods."""
try:
from keyboard_shortcuts import KeyboardShortcutManager
manager = KeyboardShortcutManager()
# Test that required methods exist
self.assertTrue(hasattr(manager, 'get_shortcuts_js'))
self.assertTrue(hasattr(manager, 'setEnabled'))
self.assertTrue(hasattr(manager, 'updateShortcuts'))
# Test method calls
self.assertIsNotNone(manager.get_shortcuts_js())
print('✓ KeyboardShortcutManager methods validated')
except Exception as e:
self.fail(f'KeyboardShortcutManager method test failed: {e}')
def test_screen_reader_methods(self):
"""Test that ScreenReaderSupportManager has required methods."""
try:
from screen_reader_support import ScreenReaderManager
manager = ScreenReaderManager()
# Test that required methods exist
self.assertTrue(hasattr(manager, 'get_screen_reader_js'))
self.assertTrue(hasattr(manager, 'enhanceFormElements'))
self.assertTrue(hasattr(manager, 'generateId'))
print('✓ ScreenReaderSupportManager methods validated')
except Exception as e:
self.fail(f'ScreenReaderSupportManager method test failed: {e}')
def test_user_preferences_initialization(self):
"""Test that UserPreferencesManager initializes correctly."""
try:
from user_preferences import UserPreferencesManager
# Test initialization without Flask app
manager = UserPreferencesManager()
self.assertTrue(hasattr(manager, 'preferences'))
self.assertIsInstance(manager.preferences, dict)
self.assertGreater(len(manager.preferences), 0)
print('✓ UserPreferencesManager initialization validated')
except Exception as e:
self.fail(f'UserPreferencesManager initialization test failed: {e}')
if __name__ == '__main__':
# Configure test runner
unittest.main(verbosity=2, buffer=True)