|
|
|
|
|
""" |
|
|
Test script to validate the FastAPI application |
|
|
""" |
|
|
import sys |
|
|
import os |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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_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) |
|
|
|
|
|
|