File size: 2,989 Bytes
5bacd22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/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)