-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runner.py
More file actions
98 lines (82 loc) · 2.84 KB
/
test_runner.py
File metadata and controls
98 lines (82 loc) · 2.84 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
#!/usr/bin/env python3
"""
Simple test runner script to demonstrate the endpoint tester
"""
import asyncio
import sys
from pathlib import Path
# Add current directory to path for imports
sys.path.append(str(Path(__file__).parent))
from main import EndpointTesterApp
async def run_demo():
"""Run a demonstration of the endpoint tester"""
print("=== Endpoint Performance Tester Demo ===")
print("This demo will test some public APIs to show the functionality")
print()
# Create app instance
app = EndpointTesterApp()
# Create a demo test configuration
demo_config = {
"name": "Demo API Test",
"base_url": "https://httpbin.org",
"concurrent_requests": 2,
"test_duration_seconds": 10,
"warmup_requests": 1,
"description": "Demo test using httpbin.org",
"endpoints": [
{
"name": "Get Request",
"url": "/get",
"method": "GET",
"expected_status_code": 200,
"description": "Test GET request",
"timeout": 5
},
{
"name": "Post Request",
"url": "/post",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"json_data": {
"test": "data",
"timestamp": "2024-01-01"
},
"expected_status_code": 200,
"description": "Test POST request",
"timeout": 5
},
{
"name": "Delay Request",
"url": "/delay/1",
"method": "GET",
"expected_status_code": 200,
"description": "Test request with 1 second delay",
"timeout": 5
}
]
}
# Create test suite from config
test_suite = app.test_manager.create_test_suite_from_dict(demo_config)
app.test_manager.add_test_suite(test_suite)
print(f"Running demo test: {test_suite.name}")
print(f"Duration: {test_suite.test_duration_seconds} seconds")
print(f"Concurrent requests: {test_suite.concurrent_requests}")
print(f"Endpoints: {len(test_suite.endpoints)}")
print()
# Run the test
result = await app.test_manager.run_test_suite(test_suite.name)
if result:
print("\n" + "="*60)
print("DEMO COMPLETED SUCCESSFULLY!")
print("="*60)
# Display results
app.result_display.display_test_suite_result(result, detailed=True)
# Export results
app._export_results(result)
print("\nDemo completed! Check the generated files for detailed results.")
else:
print("Demo failed!")
if __name__ == "__main__":
asyncio.run(run_demo())