137 lines
4.7 KiB
Python
137 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Basic test to verify refactored modules can be imported and initialized
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add src to path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
def test_imports():
|
|
"""Test that all refactored modules can be imported"""
|
|
print("🧪 Testing module imports...")
|
|
|
|
try:
|
|
# Test core modules
|
|
from core.config import config
|
|
from core.logging_config import setup_logging
|
|
from core.signal_handling import register_signal_handlers
|
|
print("✅ Core modules imported successfully")
|
|
|
|
# Test database modules
|
|
from database import DatabaseManager, DatabaseHelper
|
|
print("✅ Database modules imported successfully")
|
|
|
|
# Test SMS services
|
|
from services.sms import SMSConnectionManager, SMSSender, ConnectionType, SMSResult
|
|
print("✅ SMS service modules imported successfully")
|
|
|
|
# Test campaign services
|
|
from services.campaign import CampaignManager, CampaignExecutor, MessageUtils
|
|
print("✅ Campaign service modules imported successfully")
|
|
|
|
# Test response sync service
|
|
from services.response_sync import ResponseSyncService
|
|
print("✅ Response sync service imported successfully")
|
|
|
|
# Test background services
|
|
from services.background import PhoneMonitor
|
|
print("✅ Background service modules imported successfully")
|
|
|
|
return True
|
|
|
|
except ImportError as e:
|
|
print(f"❌ Import error: {e}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Unexpected error: {e}")
|
|
return False
|
|
|
|
def test_initialization():
|
|
"""Test that key classes can be initialized"""
|
|
print("\n🧪 Testing module initialization...")
|
|
|
|
try:
|
|
from core.config import config
|
|
from database import DatabaseManager, DatabaseHelper
|
|
from services.sms import SMSConnectionManager
|
|
|
|
# Test database manager
|
|
db_manager = DatabaseManager(config.DATABASE)
|
|
print("✅ DatabaseManager initialized")
|
|
|
|
# Test database helper
|
|
db_helper = DatabaseHelper(config.DATABASE)
|
|
print("✅ DatabaseHelper initialized")
|
|
|
|
# Test SMS connection manager
|
|
sms_manager = SMSConnectionManager(config.termux_config)
|
|
print("✅ SMSConnectionManager initialized")
|
|
|
|
# Test campaign manager (requires db_helper and sms_manager)
|
|
from services.campaign import CampaignManager
|
|
campaign_manager = CampaignManager(db_helper, sms_manager)
|
|
print("✅ CampaignManager initialized")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Initialization error: {e}")
|
|
return False
|
|
|
|
def test_basic_functionality():
|
|
"""Test basic functionality of key components"""
|
|
print("\n🧪 Testing basic functionality...")
|
|
|
|
try:
|
|
from core.config import config
|
|
from services.campaign.message_utils import MessageUtils
|
|
|
|
# Test message substitution
|
|
template = "Hi {name}! Your phone is {phone}. Today is {date}."
|
|
result = MessageUtils.substitute_variables(template, name="John", phone="1234567890")
|
|
|
|
expected_parts = ["Hi John!", "Your phone is 1234567890", "Today is"]
|
|
if all(part in result for part in expected_parts):
|
|
print("✅ Message substitution working")
|
|
else:
|
|
print(f"❌ Message substitution failed: {result}")
|
|
return False
|
|
|
|
# Test response classification
|
|
positive_response = MessageUtils.classify_response("Yes, I'm interested!")
|
|
if positive_response == 'positive':
|
|
print("✅ Response classification working")
|
|
else:
|
|
print(f"❌ Response classification failed: {positive_response}")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Functionality test error: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 Starting refactoring verification tests...\n")
|
|
|
|
# Run tests
|
|
imports_ok = test_imports()
|
|
init_ok = test_initialization()
|
|
func_ok = test_basic_functionality()
|
|
|
|
# Summary
|
|
print("\n📊 Test Results:")
|
|
print(f" Imports: {'✅ PASS' if imports_ok else '❌ FAIL'}")
|
|
print(f" Initialization: {'✅ PASS' if init_ok else '❌ FAIL'}")
|
|
print(f" Functionality: {'✅ PASS' if func_ok else '❌ FAIL'}")
|
|
|
|
if imports_ok and init_ok and func_ok:
|
|
print("\n🎉 All tests passed! Refactoring is working correctly.")
|
|
sys.exit(0)
|
|
else:
|
|
print("\n⚠️ Some tests failed. Check the errors above.")
|
|
sys.exit(1)
|