Lin / test_scheduler_integration.py
Zelyanoth's picture
ikk
98b8066
raw
history blame
2.91 kB
#!/usr/bin/env python3
"""
Integration test for APScheduler with Flask application.
Tests the actual application startup and scheduler initialization.
"""
import sys
import os
import subprocess
import time
from pathlib import Path
def test_app_startup_with_scheduler():
"""Test that the Flask application starts with APScheduler visible."""
try:
# Change to the project directory
project_dir = Path(__file__).parent
os.chdir(project_dir)
# Start the application
print("πŸš€ Starting Flask application with APScheduler...")
process = subprocess.Popen(
[sys.executable, "start_app.py"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
universal_newlines=True
)
# Wait for startup and capture output
startup_timeout = 30 # 30 seconds timeout
start_time = time.time()
scheduler_found = False
verification_found = False
while time.time() - start_time < startup_timeout:
output = process.stdout.readline()
if output:
print(output.strip())
# Check for APScheduler initialization messages
if "Initializing APScheduler" in output:
scheduler_found = True
print("βœ… APScheduler initialization message found!")
# Check for verification messages
if "βœ… APScheduler initialized successfully" in output:
verification_found = True
print("βœ… APScheduler verification message found!")
# Check for successful startup
if "running on http" in output.lower():
break
# Terminate the process
process.terminate()
process.wait(timeout=10)
if scheduler_found and verification_found:
print("βœ… APScheduler is visible during application startup")
return True
else:
print("❌ APScheduler messages not found in startup logs")
return False
except Exception as e:
print(f"❌ Error testing app startup: {e}")
return False
def main():
"""Main integration test function."""
print("πŸ”— Testing APScheduler integration with Flask application...")
print("=" * 60)
success = test_app_startup_with_scheduler()
print("\n" + "=" * 60)
if success:
print("πŸŽ‰ Integration test passed! APScheduler is working in the Flask app.")
else:
print("⚠️ Integration test failed. APScheduler may not be properly configured.")
return success
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)