wound-app / test_app.py
Ani14's picture
Upload 4 files
5bacd22 verified
#!/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)