#!/usr/bin/env python3 """ Test script to validate the FastAPI application """ import sys import os # Add the current directory to Python path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def test_import(): """Test if the main module can be imported without errors""" try: from main import app print("✅ Successfully imported FastAPI app") return True except Exception as e: print(f"❌ Failed to import FastAPI app: {e}") return False def test_endpoints(): """Test if endpoints are properly defined""" try: from main import app routes = [route.path for route in app.routes] print(f"✅ Found {len(routes)} routes defined") # Check for some key endpoints key_endpoints = [ "/send_email", "/verify_license_key", "/add_patient", "/add_wound_details", "/get_all_patient_details" ] missing_endpoints = [] for endpoint in key_endpoints: if endpoint not in routes: missing_endpoints.append(endpoint) if missing_endpoints: print(f"❌ Missing endpoints: {missing_endpoints}") return False else: print("✅ All key endpoints are defined") return True except Exception as e: print(f"❌ Failed to check endpoints: {e}") return False def test_pydantic_models(): """Test if Pydantic models are properly defined""" try: from main import SendEmailRequest, AddPatientRequest, AddWoundDetailsRequest print("✅ Pydantic models imported successfully") # Test model instantiation test_email_request = SendEmailRequest( name="Test", email="test@example.com", c_code="+1", phone="1234567890" ) print("✅ Pydantic model validation works") return True except Exception as e: print(f"❌ Failed to test Pydantic models: {e}") return False def main(): """Run all tests""" print("🧪 Testing FastAPI Application...") print("=" * 50) tests = [ ("Import Test", test_import), ("Endpoints Test", test_endpoints), ("Pydantic Models Test", test_pydantic_models) ] passed = 0 total = len(tests) for test_name, test_func in tests: print(f"\n🔍 Running {test_name}...") if test_func(): passed += 1 print("\n" + "=" * 50) print(f"📊 Test Results: {passed}/{total} tests passed") if passed == total: print("🎉 All tests passed! FastAPI application is ready.") return True else: print("⚠️ Some tests failed. Please check the errors above.") return False if __name__ == "__main__": success = main() sys.exit(0 if success else 1)