-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_functionality.py
More file actions
146 lines (122 loc) Β· 4.29 KB
/
Copy pathtest_functionality.py
File metadata and controls
146 lines (122 loc) Β· 4.29 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
"""
Comprehensive functionality test for PathPilot backend
"""
import requests
import json
import time
BASE_URL = "http://localhost:5000/api"
def test_health():
"""Test health endpoint"""
print("π Testing Health Endpoint...")
response = requests.get(f"{BASE_URL}/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
print("β
Health check passed")
def test_registration():
"""Test user registration"""
print("π Testing User Registration...")
data = {
"name": "Test User",
"email": "test@example.com",
"password": "testpass123"
}
response = requests.post(f"{BASE_URL}/auth/register", json=data)
assert response.status_code == 201
data = response.json()
assert "access_token" in data
print("β
Registration passed")
return data["access_token"]
def test_login():
"""Test user login"""
print("π Testing User Login...")
data = {
"email": "test@example.com",
"password": "testpass123"
}
response = requests.post(f"{BASE_URL}/auth/login", json=data)
assert response.status_code == 200
data = response.json()
assert "access_token" in data
print("β
Login passed")
return data["access_token"]
def test_user_profile(token):
"""Test getting user profile"""
print("π Testing User Profile...")
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(f"{BASE_URL}/auth/me", headers=headers)
assert response.status_code == 200
data = response.json()
assert "user" in data
print("β
User profile passed")
def test_chat(token):
"""Test chat functionality"""
print("π Testing Chat Functionality...")
headers = {"Authorization": f"Bearer {token}"}
data = {"message": "Hello, I need career advice"}
response = requests.post(f"{BASE_URL}/chat", json=data, headers=headers)
assert response.status_code == 200
data = response.json()
assert "response" in data
assert "timestamp" in data
print("β
Chat functionality passed")
def test_career_recommendations(token):
"""Test career recommendations"""
print("π Testing Career Recommendations...")
headers = {"Authorization": f"Bearer {token}"}
data = {
"interests": ["technology", "programming"],
"skills": ["Python", "JavaScript"],
"experience": "beginner"
}
response = requests.post(f"{BASE_URL}/career-recommendations", json=data, headers=headers)
assert response.status_code == 200
data = response.json()
assert "recommendations" in data
assert len(data["recommendations"]) > 0
print("β
Career recommendations passed")
def test_error_handling():
"""Test error handling"""
print("π Testing Error Handling...")
# Test invalid registration
response = requests.post(f"{BASE_URL}/auth/register", json={})
assert response.status_code == 400
# Test invalid login
response = requests.post(f"{BASE_URL}/auth/login", json={})
assert response.status_code == 400
# Test unauthorized access
response = requests.get(f"{BASE_URL}/auth/me")
assert response.status_code == 401
print("β
Error handling passed")
def main():
"""Run all tests"""
print("π Starting PathPilot Functionality Tests...\n")
try:
# Test health endpoint
test_health()
# Test registration and login
token = test_registration()
# Test user profile
test_user_profile(token)
# Test chat functionality
test_chat(token)
# Test career recommendations
test_career_recommendations(token)
# Test error handling
test_error_handling()
print("\nπ All tests passed! PathPilot is working correctly.")
print("\nπ Test Summary:")
print("β
Health endpoint")
print("β
User registration")
print("β
User login")
print("β
User profile")
print("β
Chat functionality")
print("β
Career recommendations")
print("β
Error handling")
except Exception as e:
print(f"\nβ Test failed: {str(e)}")
return False
return True
if __name__ == "__main__":
main()