-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_422_errors.py
More file actions
137 lines (114 loc) Β· 4.35 KB
/
debug_422_errors.py
File metadata and controls
137 lines (114 loc) Β· 4.35 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
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
"""
Debug 422 validation errors in generation endpoint
"""
import requests
import json
import time
# Test configuration
API_BASE_URL = "http://127.0.0.1:8000"
def test_auth_and_project():
"""Test authentication and project creation only"""
print("π Testing Authentication...")
# Test authentication
auth_data = {
"username": "testuser2024",
"password": "TestPassword123!"
}
response = requests.post(f"{API_BASE_URL}/auth/login", data=auth_data)
print(f"Auth response: {response.status_code}")
if response.status_code != 200:
print(f"Auth failed: {response.text}")
return None, None
token = response.json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
print("β
Authentication successful")
# Test project creation
print("π Testing Project Creation...")
project_data = {
"name": "Test E-commerce Backend",
"description": "Test project for comprehensive pipeline validation",
"domain": "ecommerce",
"tech_stack": ["fastapi", "postgresql", "pydantic"],
"constraints": {
"max_file_size": 50,
"include_tests": True,
"include_documentation": True
}
}
response = requests.post(f"{API_BASE_URL}/projects/", json=project_data, headers=headers)
print(f"Project response: {response.status_code}")
if response.status_code != 201:
print(f"Project creation failed: {response.text}")
return None, None
project_id = response.json()["id"]
print(f"β
Project created: {project_id}")
return headers, project_id
def test_generation_minimal():
"""Test generation with minimal data"""
headers, project_id = test_auth_and_project()
if not headers or not project_id:
return
print("π€ Testing Minimal Generation Request...")
# Minimal generation data
generation_data = {
"prompt": "Create a simple FastAPI hello world endpoint",
"project_id": project_id
}
response = requests.post(f"{API_BASE_URL}/ai/generate", json=generation_data, headers=headers)
print(f"Generation response: {response.status_code}")
print(f"Response body: {response.text}")
if response.status_code == 422:
try:
error_detail = response.json()
print("π Validation errors:")
for error in error_detail.get("detail", []):
print(f" β’ {error}")
except:
pass
def test_generation_full():
"""Test generation with full data"""
headers, project_id = test_auth_and_project()
if not headers or not project_id:
return
print("π€ Testing Full Generation Request...")
# Full generation data
generation_data = {
"prompt": "Create a FastAPI e-commerce backend with user authentication, product catalog, shopping cart, and order management. Include PostgreSQL database models, Pydantic schemas, CRUD operations, and API endpoints.",
"project_id": project_id,
"context": {
"domain": "ecommerce",
"tech_stack": "fastapi_postgresql",
"features": ["authentication", "products", "cart", "orders"],
"requirements": [
"RESTful API design",
"JWT authentication",
"Database migrations",
"Input validation",
"Error handling"
]
},
"is_iteration": False,
"parent_generation_id": None
}
response = requests.post(f"{API_BASE_URL}/ai/generate", json=generation_data, headers=headers)
print(f"Generation response: {response.status_code}")
print(f"Response body: {response.text}")
if response.status_code == 422:
try:
error_detail = response.json()
print("π Validation errors:")
for error in error_detail.get("detail", []):
print(f" β’ {error}")
except:
pass
if __name__ == "__main__":
print("π Debugging Generation Endpoint 422 Errors")
print("=" * 50)
# Wait for server
print("β³ Waiting for server...")
time.sleep(3)
print("\n1. Testing minimal generation request:")
test_generation_minimal()
print("\n2. Testing full generation request:")
test_generation_full()