Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,13 @@ def validate_json_response(expected, actual):
|
|
| 24 |
except Exception as e:
|
| 25 |
return False, f"Invalid JSON: {str(e)}"
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def run_single_test(endpoint, method, bearer_token,
|
| 28 |
expected_status, expected_body,
|
| 29 |
payload=None, test_name=None):
|
|
@@ -44,6 +51,13 @@ def run_single_test(endpoint, method, bearer_token,
|
|
| 44 |
if bearer_token and bearer_token.strip():
|
| 45 |
headers['Authorization'] = f'Bearer {bearer_token.strip()}'
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
data, json_payload = None, None
|
| 48 |
if payload and isinstance(payload, str) and payload.strip():
|
| 49 |
if payload.lower().startswith("header:"):
|
|
@@ -175,6 +189,7 @@ def process_file(file, bearer_token: str):
|
|
| 175 |
- ✅ Passed: {len(results_df[results_df['Outcome']=="PASS"])}
|
| 176 |
- ❌ Failed: {len(results_df[results_df['Outcome']=="FAIL"])}
|
| 177 |
- ⚠️ Uncertain: {len(results_df[results_df['Outcome']=="UNCERTAIN"])}
|
|
|
|
| 178 |
"""
|
| 179 |
return results_df, summary
|
| 180 |
except Exception as e:
|
|
@@ -203,7 +218,7 @@ with gr.Blocks(css="* { font-family: 'Times New Roman', serif; }") as app:
|
|
| 203 |
|
| 204 |
with gr.Tab("Results"):
|
| 205 |
summary_output = gr.Markdown()
|
| 206 |
-
|
| 207 |
headers=['TestName','Endpoint','Method','Expected Status','Actual Status','Outcome','Similarity','Notes'],
|
| 208 |
interactive=False
|
| 209 |
)
|
|
|
|
| 24 |
except Exception as e:
|
| 25 |
return False, f"Invalid JSON: {str(e)}"
|
| 26 |
|
| 27 |
+
def check_connectivity(endpoint, headers):
|
| 28 |
+
try:
|
| 29 |
+
resp = requests.head(endpoint, headers=headers, timeout=5)
|
| 30 |
+
return True, resp.status_code
|
| 31 |
+
except requests.exceptions.RequestException as e:
|
| 32 |
+
return False, str(e)
|
| 33 |
+
|
| 34 |
def run_single_test(endpoint, method, bearer_token,
|
| 35 |
expected_status, expected_body,
|
| 36 |
payload=None, test_name=None):
|
|
|
|
| 51 |
if bearer_token and bearer_token.strip():
|
| 52 |
headers['Authorization'] = f'Bearer {bearer_token.strip()}'
|
| 53 |
|
| 54 |
+
# Connectivity pre-check
|
| 55 |
+
reachable, info = check_connectivity(endpoint, headers)
|
| 56 |
+
if not reachable:
|
| 57 |
+
result['Outcome'] = 'UNREACHABLE'
|
| 58 |
+
result['Notes'] = f'Cannot reach endpoint: {info}'
|
| 59 |
+
return result
|
| 60 |
+
|
| 61 |
data, json_payload = None, None
|
| 62 |
if payload and isinstance(payload, str) and payload.strip():
|
| 63 |
if payload.lower().startswith("header:"):
|
|
|
|
| 189 |
- ✅ Passed: {len(results_df[results_df['Outcome']=="PASS"])}
|
| 190 |
- ❌ Failed: {len(results_df[results_df['Outcome']=="FAIL"])}
|
| 191 |
- ⚠️ Uncertain: {len(results_df[results_df['Outcome']=="UNCERTAIN"])}
|
| 192 |
+
- 🚫 Unreachable: {len(results_df[results_df['Outcome']=="UNREACHABLE"])}
|
| 193 |
"""
|
| 194 |
return results_df, summary
|
| 195 |
except Exception as e:
|
|
|
|
| 218 |
|
| 219 |
with gr.Tab("Results"):
|
| 220 |
summary_output = gr.Markdown()
|
| 221 |
+
results_output = gr.Dataframe(
|
| 222 |
headers=['TestName','Endpoint','Method','Expected Status','Actual Status','Outcome','Similarity','Notes'],
|
| 223 |
interactive=False
|
| 224 |
)
|