Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
+
from jsonschema import validate, ValidationError
|
| 5 |
+
|
| 6 |
+
def run_tests(file):
|
| 7 |
+
results = []
|
| 8 |
+
with open(file.name, "r") as f:
|
| 9 |
+
test_cases = json.load(f)
|
| 10 |
+
|
| 11 |
+
for case in test_cases:
|
| 12 |
+
try:
|
| 13 |
+
response = requests.request(
|
| 14 |
+
method=case["method"],
|
| 15 |
+
url=f"http://your-api-domain.com{case['endpoint']}", # Replace with your deployed .NET API URL
|
| 16 |
+
json=case["payload"]
|
| 17 |
+
)
|
| 18 |
+
validate(instance=response.json(), schema=case["expected_schema"])
|
| 19 |
+
results.append(f"{case['endpoint']} β
Passed")
|
| 20 |
+
except ValidationError as e:
|
| 21 |
+
results.append(f"{case['endpoint']} β Failed: {e.message}")
|
| 22 |
+
except Exception as e:
|
| 23 |
+
results.append(f"{case['endpoint']} β Error: {str(e)}")
|
| 24 |
+
|
| 25 |
+
return "\n".join(results)
|
| 26 |
+
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=run_tests,
|
| 29 |
+
inputs=gr.File(label="Upload Test Case JSON"),
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="AI-Powered Test Runner",
|
| 32 |
+
description="Upload a JSON file with test cases to validate your .NET/React API."
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
demo.launch()
|