1-
1+ #!/usr/bin/env python3
2+ """
3+ Simple test script to verify the authentication system setup.
4+ This script checks if all required modules can be imported and basic functionality works.
5+ """
6+
7+ import sys
8+ import os
9+
10+ def test_imports ():
11+ """Test if all required modules can be imported"""
12+ print ("Testing imports..." )
13+
14+ try :
15+ import firebase_admin
16+ print ("✅ firebase-admin imported successfully" )
17+ except ImportError as e :
18+ print (f"❌ firebase-admin import failed: { e } " )
19+ return False
20+
21+ try :
22+ import jwt
23+ print ("✅ PyJWT imported successfully" )
24+ except ImportError as e :
25+ print (f"❌ PyJWT import failed: { e } " )
26+ return False
27+
28+ try :
29+ from app .auth .models import UserSignupRequest , UserLoginRequest
30+ print ("✅ Auth models imported successfully" )
31+ except ImportError as e :
32+ print (f"❌ Auth models import failed: { e } " )
33+ return False
34+
35+ try :
36+ from app .auth .firebase_auth import FirebaseAuthService
37+ print ("✅ Firebase auth service imported successfully" )
38+ except ImportError as e :
39+ print (f"❌ Firebase auth service import failed: { e } " )
40+ return False
41+
42+ try :
43+ from app .auth .dependencies import get_current_user
44+ print ("✅ Auth dependencies imported successfully" )
45+ except ImportError as e :
46+ print (f"❌ Auth dependencies import failed: { e } " )
47+ return False
48+
49+ try :
50+ from app .main import app
51+ print ("✅ FastAPI app imported successfully" )
52+ except ImportError as e :
53+ print (f"❌ FastAPI app import failed: { e } " )
54+ return False
55+
56+ return True
57+
58+
59+ def test_environment_variables ():
60+ """Test if required environment variables are set"""
61+ print ("\n Testing environment variables..." )
62+
63+ required_vars = [
64+ "JWT_SECRET" ,
65+ "FIREBASE_CREDENTIALS" ,
66+ "FIREBASE_SERVICE_ACCOUNT_PATH"
67+ ]
68+
69+ missing_vars = []
70+ for var in required_vars :
71+ if not os .getenv (var ):
72+ missing_vars .append (var )
73+
74+ if missing_vars :
75+ print (f"⚠️ Missing environment variables: { ', ' .join (missing_vars )} " )
76+ print (" These are required for full functionality" )
77+ return False
78+ else :
79+ print ("✅ All required environment variables are set" )
80+ return True
81+
82+
83+ def test_fastapi_app ():
84+ """Test if FastAPI app can be created"""
85+ print ("\n Testing FastAPI app..." )
86+
87+ try :
88+ from app .main import app
89+ routes = [route .path for route in app .routes ]
90+ print (f"✅ FastAPI app created successfully with { len (routes )} routes" )
91+
92+ # Check for auth routes
93+ auth_routes = [route for route in routes if route .startswith ('/auth' )]
94+ print (f"✅ Found { len (auth_routes )} authentication routes" )
95+
96+ return True
97+ except Exception as e :
98+ print (f"❌ FastAPI app test failed: { e } " )
99+ return False
100+
101+
102+ def main ():
103+ """Run all tests"""
104+ print ("🔍 Testing Authentication System Setup\n " )
105+
106+ tests = [
107+ test_imports ,
108+ test_environment_variables ,
109+ test_fastapi_app
110+ ]
111+
112+ passed = 0
113+ total = len (tests )
114+
115+ for test in tests :
116+ try :
117+ if test ():
118+ passed += 1
119+ except Exception as e :
120+ print (f"❌ Test failed with exception: { e } " )
121+
122+ print (f"\n 📊 Test Results: { passed } /{ total } tests passed" )
123+
124+ if passed == total :
125+ print ("🎉 All tests passed! The authentication system is ready to use." )
126+ print ("\n Next steps:" )
127+ print ("1. Configure your Firebase project" )
128+ print ("2. Set up environment variables in .env file" )
129+ print ("3. Run: python run.py" )
130+ print ("4. Visit: http://localhost:8000/docs" )
131+ else :
132+ print ("⚠️ Some tests failed. Please check the errors above." )
133+ sys .exit (1 )
134+
135+
136+ if __name__ == "__main__" :
137+ main ()
0 commit comments