n8n-dan / test_app.py
danilonovais's picture
Upload 7 files
a9f0f7c verified
raw
history blame
4.62 kB
#!/usr/bin/env python3
"""
Simple test script to verify the app works correctly
"""
import os
import sys
import asyncio
from pathlib import Path
# Add the current directory to path
sys.path.insert(0, str(Path(__file__).parent))
def test_imports():
"""Test that all required modules can be imported."""
print("πŸ§ͺ Testing imports...")
try:
import fastapi
print("βœ… FastAPI imported successfully")
except ImportError as e:
print(f"❌ FastAPI import failed: {e}")
return False
try:
import uvicorn
print("βœ… Uvicorn imported successfully")
except ImportError as e:
print(f"❌ Uvicorn import failed: {e}")
return False
try:
import pydantic
print("βœ… Pydantic imported successfully")
except ImportError as e:
print(f"❌ Pydantic import failed: {e}")
return False
try:
# Test PostgreSQL drivers
import psycopg2
print("βœ… PostgreSQL driver (psycopg2) imported successfully")
except ImportError as e:
print(f"⚠️ PostgreSQL driver (psycopg2) not available: {e}")
try:
import asyncpg
print("βœ… Async PostgreSQL driver (asyncpg) imported successfully")
except ImportError as e:
print(f"⚠️ Async PostgreSQL driver (asyncpg) not available: {e}")
return True
def test_app_creation():
"""Test that the app can be created without errors."""
print("\nπŸ§ͺ Testing app creation...")
try:
# Set test environment
os.environ["DB_TYPE"] = "sqlite"
os.environ["WORKFLOW_DB_PATH"] = "test_database.db"
# Import the app
from app import load_environment
load_environment()
print("βœ… Environment loading works")
# Try to import the api_server
from api_server import app
print("βœ… FastAPI app created successfully")
return True
except Exception as e:
print(f"❌ App creation failed: {e}")
import traceback
traceback.print_exc()
return False
def test_database():
"""Test database connectivity."""
print("\nπŸ§ͺ Testing database...")
try:
from workflow_db import WorkflowDatabase
# Test SQLite (should always work)
db = WorkflowDatabase("test_workflows.db")
print("βœ… SQLite database connection works")
# Clean up
test_db = Path("test_workflows.db")
if test_db.exists():
test_db.unlink()
return True
except Exception as e:
print(f"❌ Database test failed: {e}")
return False
async def test_startup():
"""Test the startup tasks."""
print("\nπŸ§ͺ Testing startup tasks...")
try:
from app import startup_tasks
await startup_tasks()
print("βœ… Startup tasks completed successfully")
return True
except Exception as e:
print(f"❌ Startup tasks failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests."""
print("πŸš€ N8N Workflow API - Testing Suite")
print("=" * 50)
tests = [
("Import Tests", test_imports),
("App Creation", test_app_creation),
("Database Tests", test_database),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\nπŸ“‹ Running {test_name}...")
try:
if test_func():
passed += 1
print(f"βœ… {test_name} PASSED")
else:
print(f"❌ {test_name} FAILED")
except Exception as e:
print(f"❌ {test_name} FAILED with exception: {e}")
# Test async startup
print(f"\nπŸ“‹ Running Startup Tests...")
try:
if asyncio.run(test_startup()):
passed += 1
print(f"βœ… Startup Tests PASSED")
else:
print(f"❌ Startup Tests FAILED")
total += 1
except Exception as e:
print(f"❌ Startup Tests FAILED with exception: {e}")
total += 1
print("\n" + "=" * 50)
print(f"πŸ“Š Test Results: {passed}/{total} tests passed")
if passed == total:
print("πŸŽ‰ All tests passed! The app is ready for deployment.")
return True
else:
print("⚠️ Some tests failed. Check the output above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)