Spaces:
Paused
Paused
Update admin_routes.py
Browse files- admin_routes.py +40 -7
admin_routes.py
CHANGED
|
@@ -1142,7 +1142,10 @@ async def spark_delete_project(project_name: str, username: str = Depends(verify
|
|
| 1142 |
return await _spark_project_control("delete", project_name, username)
|
| 1143 |
|
| 1144 |
# ===================== Test Endpoints =====================
|
| 1145 |
-
|
|
|
|
|
|
|
|
|
|
| 1146 |
async def test_api(api_data: dict = Body(...), username: str = Depends(verify_token)):
|
| 1147 |
"""Test API endpoint with auth support"""
|
| 1148 |
import requests
|
|
@@ -1228,7 +1231,7 @@ async def test_api(api_data: dict = Body(...), username: str = Depends(verify_to
|
|
| 1228 |
proxies={"http": api.proxy, "https": api.proxy} if api.proxy else None
|
| 1229 |
)
|
| 1230 |
|
| 1231 |
-
|
| 1232 |
|
| 1233 |
# Prepare response body
|
| 1234 |
try:
|
|
@@ -1239,20 +1242,50 @@ async def test_api(api_data: dict = Body(...), username: str = Depends(verify_to
|
|
| 1239 |
# Check if request was successful (2xx status codes)
|
| 1240 |
is_success = 200 <= response.status_code < 300
|
| 1241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1242 |
result = {
|
| 1243 |
"success": is_success,
|
| 1244 |
"status_code": response.status_code,
|
| 1245 |
-
"
|
| 1246 |
-
"
|
| 1247 |
-
"
|
| 1248 |
-
"
|
|
|
|
| 1249 |
}
|
| 1250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1251 |
# Add error info for non-2xx responses
|
| 1252 |
if not is_success:
|
| 1253 |
result["error"] = f"HTTP {response.status_code}: {response.reason}"
|
| 1254 |
|
| 1255 |
-
log(f"📋 Test result: {response.status_code} in {
|
| 1256 |
return result
|
| 1257 |
|
| 1258 |
except requests.exceptions.Timeout:
|
|
|
|
| 1142 |
return await _spark_project_control("delete", project_name, username)
|
| 1143 |
|
| 1144 |
# ===================== Test Endpoints =====================
|
| 1145 |
+
Backend'de test API endpoint'inde response detaylarını döndürmemiz gerekiyor. admin_routes.py dosyasındaki test_api fonksiyonunu güncelleyelim:
|
| 1146 |
+
admin_routes.py (KISMI)
|
| 1147 |
+
test_api fonksiyonunu şu şekilde güncelleyelim:
|
| 1148 |
+
[email protected]("/apis/test")
|
| 1149 |
async def test_api(api_data: dict = Body(...), username: str = Depends(verify_token)):
|
| 1150 |
"""Test API endpoint with auth support"""
|
| 1151 |
import requests
|
|
|
|
| 1231 |
proxies={"http": api.proxy, "https": api.proxy} if api.proxy else None
|
| 1232 |
)
|
| 1233 |
|
| 1234 |
+
response_time = int((time.time() - start_time) * 1000)
|
| 1235 |
|
| 1236 |
# Prepare response body
|
| 1237 |
try:
|
|
|
|
| 1242 |
# Check if request was successful (2xx status codes)
|
| 1243 |
is_success = 200 <= response.status_code < 300
|
| 1244 |
|
| 1245 |
+
# Extract values if response mappings are defined
|
| 1246 |
+
extracted_values = []
|
| 1247 |
+
if api.response_mappings and isinstance(response_body, dict):
|
| 1248 |
+
from jsonpath_ng import parse
|
| 1249 |
+
for mapping in api.response_mappings:
|
| 1250 |
+
try:
|
| 1251 |
+
jsonpath_expr = parse(mapping['json_path'])
|
| 1252 |
+
matches = jsonpath_expr.find(response_body)
|
| 1253 |
+
value = matches[0].value if matches else None
|
| 1254 |
+
extracted_values.append({
|
| 1255 |
+
"variable_name": mapping['variable_name'],
|
| 1256 |
+
"value": value,
|
| 1257 |
+
"type": mapping['type'],
|
| 1258 |
+
"caption": mapping.get('caption', '')
|
| 1259 |
+
})
|
| 1260 |
+
except Exception as e:
|
| 1261 |
+
log(f"Failed to extract {mapping['variable_name']}: {e}")
|
| 1262 |
+
extracted_values.append({
|
| 1263 |
+
"variable_name": mapping['variable_name'],
|
| 1264 |
+
"value": None,
|
| 1265 |
+
"error": str(e),
|
| 1266 |
+
"type": mapping['type'],
|
| 1267 |
+
"caption": mapping.get('caption', '')
|
| 1268 |
+
})
|
| 1269 |
+
|
| 1270 |
result = {
|
| 1271 |
"success": is_success,
|
| 1272 |
"status_code": response.status_code,
|
| 1273 |
+
"response_time": response_time,
|
| 1274 |
+
"response_body": response_body,
|
| 1275 |
+
"response_headers": dict(response.headers),
|
| 1276 |
+
"request_body": request_body,
|
| 1277 |
+
"request_headers": headers
|
| 1278 |
}
|
| 1279 |
|
| 1280 |
+
# Add extracted values if any
|
| 1281 |
+
if extracted_values:
|
| 1282 |
+
result["extracted_values"] = extracted_values
|
| 1283 |
+
|
| 1284 |
# Add error info for non-2xx responses
|
| 1285 |
if not is_success:
|
| 1286 |
result["error"] = f"HTTP {response.status_code}: {response.reason}"
|
| 1287 |
|
| 1288 |
+
log(f"📋 Test result: {response.status_code} in {response_time}ms")
|
| 1289 |
return result
|
| 1290 |
|
| 1291 |
except requests.exceptions.Timeout:
|