-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auth.py
More file actions
81 lines (63 loc) · 2.15 KB
/
test_auth.py
File metadata and controls
81 lines (63 loc) · 2.15 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
#!/usr/bin/env python3
"""
Test script for authentication system
"""
import requests
import json
BASE_URL = "http://localhost:8000"
def test_register():
"""Test user registration"""
print("Testing user registration...")
register_data = {
"name": "احمد محمدی",
"mobile_number": "09123456789",
"password": "123456",
"email": "ahmad@example.com",
"national_code": "1234567890"
}
response = requests.post(f"{BASE_URL}/api/v1/auth/register", json=register_data)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
return response
def test_login():
"""Test user login"""
print("\nTesting user login...")
login_data = {
"mobile_number": "09123456789",
"password": "123456"
}
response = requests.post(f"{BASE_URL}/api/v1/auth/login", json=login_data)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
if response.status_code == 200:
return response.json().get("access_token")
return None
def test_get_current_user(token):
"""Test getting current user info"""
if not token:
print("No token available for testing current user")
return
print("\nTesting get current user...")
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(f"{BASE_URL}/api/v1/auth/me", headers=headers)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
def test_health():
"""Test health endpoint"""
print("Testing health endpoint...")
response = requests.get(f"{BASE_URL}/api/v1/health")
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
if __name__ == "__main__":
print("Starting authentication system tests...")
print("=" * 50)
# Test health endpoint first
test_health()
# Test registration
register_response = test_register()
# Test login
token = test_login()
# Test get current user
test_get_current_user(token)
print("\n" + "=" * 50)
print("Tests completed!")