-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
executable file
·92 lines (84 loc) · 2.99 KB
/
Copy pathtest_api.py
File metadata and controls
executable file
·92 lines (84 loc) · 2.99 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
#!/usr/bin/env python3
import requests
import json
import time
BASE_URL = "http://localhost:5045/api"
def test_api():
print("🧪 Testing Real Estate API...")
# Test 1: GET all properties
print("\n1. Testing GET /api/properties")
try:
response = requests.get(f"{BASE_URL}/properties", timeout=5)
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" Properties found: {len(data)}")
else:
print(f" Error: {response.text}")
except Exception as e:
print(f" Connection error: {e}")
# Test 2: GET all users
print("\n2. Testing GET /api/users")
try:
response = requests.get(f"{BASE_URL}/users", timeout=5)
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" Users found: {len(data)}")
else:
print(f" Error: {response.text}")
except Exception as e:
print(f" Connection error: {e}")
# Test 3: GET all realtors
print("\n3. Testing GET /api/realtors")
try:
response = requests.get(f"{BASE_URL}/realtors", timeout=5)
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" Realtors found: {len(data)}")
else:
print(f" Error: {response.text}")
except Exception as e:
print(f" Connection error: {e}")
# Test 4: POST new property
print("\n4. Testing POST /api/properties")
new_property = {
"address": "123 Test Street",
"city": "Test City",
"state": "TS",
"zipCode": "12345",
"price": 250000,
"bedrooms": 3,
"bathrooms": 2,
"squareFeet": 1500,
"propertyType": "House",
"status": "Available",
"realtorId": 1,
"description": "Test property"
}
try:
response = requests.post(f"{BASE_URL}/properties",
json=new_property,
headers={"Content-Type": "application/json"},
timeout=5)
print(f" Status: {response.status_code}")
if response.status_code in [200, 201]:
print(" ✅ Property created successfully")
else:
print(f" Error: {response.text}")
except Exception as e:
print(f" Connection error: {e}")
# Test 5: Check Swagger endpoint
print("\n5. Testing Swagger documentation")
try:
response = requests.get("http://localhost:5045/swagger/index.html", timeout=5)
print(f" Status: {response.status_code}")
if response.status_code == 200:
print(" ✅ Swagger UI accessible")
else:
print(" ❌ Swagger UI not accessible")
except Exception as e:
print(f" Connection error: {e}")
if __name__ == "__main__":
test_api()