Lin / test_apscheduler.py
Zelyanoth's picture
::
3c6e0b2
"""
Test script for APScheduler service.
This script tests the basic functionality of the APScheduler service.
"""
import sys
import os
from pathlib import Path
# Add the backend directory to the Python path
backend_dir = Path(__file__).parent / "backend"
sys.path.insert(0, str(backend_dir))
def test_apscheduler_service():
"""Test the APScheduler service."""
try:
# Import the APScheduler service
from scheduler.apscheduler_service import APSchedulerService
# Create a mock app object
class MockApp:
def __init__(self):
self.config = {
'SUPABASE_URL': 'test_url',
'SUPABASE_KEY': 'test_key',
'SCHEDULER_ENABLED': True
}
# Create a mock Supabase client
class MockSupabaseClient:
def table(self, table_name):
return self
def select(self, columns):
return self
def execute(self):
# Return mock data
return type('obj', (object,), {'data': []})()
# Initialize the scheduler service
app = MockApp()
scheduler_service = APSchedulerService()
# Mock the Supabase client initialization
scheduler_service.supabase_client = MockSupabaseClient()
# Test loading schedules
scheduler_service.load_schedules()
# Check if scheduler is initialized
if scheduler_service.scheduler is not None:
print("βœ“ APScheduler service initialized successfully")
return True
else:
print("βœ— APScheduler service failed to initialize")
return False
except Exception as e:
print(f"βœ— Error testing APScheduler service: {str(e)}")
return False
if __name__ == "__main__":
print("Testing APScheduler service...")
success = test_apscheduler_service()
if success:
print("All tests passed!")
sys.exit(0)
else:
print("Tests failed!")
sys.exit(1)