Spaces:
Sleeping
Sleeping
File size: 1,343 Bytes
950dcd2 | 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 | """Test Forge routes."""
from flask import Blueprint, render_template, request, jsonify
from .forge import generate_tests
bp = Blueprint("test_forge", __name__, template_folder="templates")
SUPPORTED_FRAMEWORKS = {
"TypeScript / Jest",
"Python / pytest",
"JavaScript / Mocha",
"Java / JUnit",
"Go / testing",
"Ruby / RSpec",
"PHP / PHPUnit",
"C# / xUnit",
}
@bp.route("/")
def index():
return render_template("test_forge/index.html")
@bp.route("/api/generate", methods=["POST"])
def api_generate():
body = request.get_json(silent=True) or {}
source_code = (body.get("source_code") or "").strip()
framework = (body.get("framework") or "Python / pytest").strip()
instructions = (body.get("instructions") or "").strip()
if not source_code:
return jsonify({"error": "source_code is required — paste your code"}), 400
if len(source_code) < 20:
return jsonify({"error": "Source code too short — paste a real function or class"}), 400
if framework not in SUPPORTED_FRAMEWORKS:
return jsonify({"error": f"Unsupported framework: {framework}"}), 400
result = generate_tests(source_code, framework, instructions)
if not result:
return jsonify({"error": "AI failed to generate tests — please try again"}), 502
return jsonify(result)
|