-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_requests.py
More file actions
83 lines (58 loc) · 2.24 KB
/
test_requests.py
File metadata and controls
83 lines (58 loc) · 2.24 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
"""Execute test requests against the Psycopg Flask app."""
import time
import requests
BASE_URL = "http://localhost:8000"
def make_request(method, endpoint, **kwargs):
"""Make HTTP request and log result."""
url = f"{BASE_URL}{endpoint}"
print(f"→ {method} {endpoint}")
# Set default timeout if not provided
kwargs.setdefault("timeout", 30)
response = requests.request(method, url, **kwargs)
print(f" Status: {response.status_code}")
time.sleep(0.5) # Small delay between requests
return response
if __name__ == "__main__":
print("Starting Psycopg test request sequence...\n")
# Execute test sequence
make_request("GET", "/health")
# Query operations
make_request("GET", "/db/query")
# Insert operations
resp1 = make_request("POST", "/db/insert", json={"name": "Alice", "email": "alice@example.com"})
resp2 = make_request("POST", "/db/insert", json={"name": "Bob", "email": "bob@example.com"})
# Batch insert
make_request(
"POST",
"/db/batch-insert",
json={
"users": [
{"name": "Charlie", "email": "charlie@example.com"},
{"name": "David", "email": "david@example.com"},
{"name": "Eve", "email": "eve@example.com"},
]
},
)
# Update operation
if resp1.status_code == 201:
user_id = resp1.json().get("id")
if user_id:
make_request("PUT", f"/db/update/{user_id}", json={"name": "Alice Updated"})
# Transaction test
make_request("POST", "/db/transaction")
# Query again to see all users
make_request("GET", "/db/query")
# Delete operation
if resp2.status_code == 201:
user_id = resp2.json().get("id")
if user_id:
make_request("DELETE", f"/db/delete/{user_id}")
make_request("GET", "/test/cursor-stream")
make_request("GET", "/test/server-cursor")
make_request("GET", "/test/copy-to")
make_request("GET", "/test/multiple-queries")
make_request("GET", "/test/pipeline-mode")
make_request("GET", "/test/dict-row-factory")
make_request("GET", "/test/namedtuple-row-factory")
make_request("GET", "/test/cursor-iteration")
print("\nAll requests completed successfully")