-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_requests.py
More file actions
127 lines (87 loc) · 3.54 KB
/
test_requests.py
File metadata and controls
127 lines (87 loc) · 3.54 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
"""Execute test requests against the Flask app to exercise the HTTPX instrumentation."""
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 test request sequence for HTTPX instrumentation...\n")
# Health check
make_request("GET", "/health")
# ==========================================================================
# Sync Client Tests
# ==========================================================================
print("\n--- Sync Client Tests ---\n")
# Basic GET request - JSON response
make_request("GET", "/api/sync/get-json")
# GET with query parameters
make_request("GET", "/api/sync/get-with-params")
# GET with custom headers
make_request("GET", "/api/sync/get-with-headers")
# POST with JSON body
make_request(
"POST",
"/api/sync/post-json",
json={"title": "Sync Test Post", "body": "This is a sync test post body", "userId": 1},
)
# POST with form data
make_request("POST", "/api/sync/post-form")
# PUT request
make_request(
"PUT",
"/api/sync/put-json",
json={"title": "Sync Updated Post", "body": "This is a sync updated post body", "userId": 1},
)
# PATCH request
make_request("PATCH", "/api/sync/patch-json", json={"title": "Sync Patched Title"})
# DELETE request
make_request("DELETE", "/api/sync/delete")
# Sequential chained requests
make_request("GET", "/api/sync/chain")
# ==========================================================================
# Async Client Tests
# ==========================================================================
print("\n--- Async Client Tests ---\n")
# Async GET request - JSON response
make_request("GET", "/api/async/get-json")
# Async GET with query parameters
make_request("GET", "/api/async/get-with-params")
# Async POST with JSON body
make_request(
"POST",
"/api/async/post-json",
json={"title": "Async Test Post", "body": "This is an async test post body", "userId": 2},
)
# Async PUT request
make_request(
"PUT",
"/api/async/put-json",
json={"title": "Async Updated Post", "body": "This is an async updated post body", "userId": 2},
)
# Async DELETE request
make_request("DELETE", "/api/async/delete")
# Parallel async requests
make_request("GET", "/api/async/parallel")
# Async sequential chained requests
make_request("GET", "/api/async/chain")
make_request("GET", "/test/streaming")
make_request("GET", "/test/toplevel-stream")
make_request("POST", "/test/multipart-files")
make_request("GET", "/test/async-send")
make_request("GET", "/test/async-stream")
make_request("GET", "/test/follow-redirects")
make_request("GET", "/test/basic-auth")
make_request("GET", "/test/event-hooks")
make_request("GET", "/test/request-hook-modify-url")
make_request("GET", "/test/digest-auth")
make_request("GET", "/test/async-hooks")
make_request("POST", "/test/file-like-body")
print("\nAll requests completed successfully")