schoolportalapi-hfe31s/test_imports.py
Automated Action f1326e83e6 Fix Pydantic BaseSettings import error and improve application startup
- Update import from pydantic.BaseSettings to pydantic_settings.BaseSettings
- Add pydantic-settings==2.1.0 to requirements.txt for Pydantic v2 compatibility
- Implement application lifespan management for database initialization
- Add init_db.py for automatic database table creation and superuser setup
- Create test_imports.py for verifying import integrity
- Ensure proper startup sequence and error handling

This fixes the health check failure caused by Pydantic v2 migration changes.

🤖 Generated with BackendIM

Co-Authored-By: BackendIM <noreply@anthropic.com>
2025-06-25 13:41:30 +00:00

42 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Test script to verify all imports work correctly."""
try:
print("Testing core imports...")
from app.core.config import settings
print("✓ Config imported successfully")
from app.core.security import create_access_token
print("✓ Security imported successfully")
print("Testing database imports...")
from app.db.base import Base
from app.db.session import SessionLocal, engine
print("✓ Database imports successful")
print("Testing model imports...")
from app.models import User, Class, Subject, Grade, Attendance, Notification
print("✓ All models imported successfully")
print("Testing schema imports...")
from app.schemas import User as UserSchema, Token
print("✓ All schemas imported successfully")
print("Testing service imports...")
from app.services.user import user_service
print("✓ All services imported successfully")
print("Testing API imports...")
from app.api.v1.api import api_router
print("✓ API router imported successfully")
print("Testing main application...")
from main import app
print("✓ Main application imported successfully")
print("\n🎉 All imports successful! Application should start correctly.")
except Exception as e:
print(f"❌ Import error: {e}")
import traceback
traceback.print_exc()