File size: 1,444 Bytes
8800c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
def test_get_public_config(client):
    """GET /api/config should return 200 with standard public configuration keys."""
    response = client.get("/api/config")
    assert response.status_code == 200
    data = response.json()
    assert isinstance(data, dict)
    assert "apiKey" in data
    assert "projectId" in data


def test_test_run_endpoint_unauthorized(client):
    """POST /api/reviews/test-run should reject unauthenticated requests with 401."""
    payload = {
        "code": "def solve(): return 1",
        "test_cases": [{"input": [], "expected": 1}],
    }
    response = client.post("/api/reviews/test-run", json=payload)
    assert response.status_code == 401
    assert "Missing or invalid Authorization header" in response.json()["detail"]


def test_test_run_endpoint_sandbox_mode(client, sandbox_headers):
    """POST /api/reviews/test-run with Bearer sandbox should execute code and return results."""
    payload = {
        "code": "def solve(x): return x * 2",
        "test_cases": [
            {"input": [2], "expected": 4},
            {"input": [5], "expected": 10},
        ],
        "timeout": 3.0,
    }
    response = client.post("/api/reviews/test-run", json=payload, headers=sandbox_headers)
    assert response.status_code == 200
    data = response.json()
    assert data["success"] is True
    assert data["status"] == "passed"
    assert data["total_tests"] == 2
    assert data["passed_count"] == 2