|
5 | 5 | import json |
6 | 6 | import zipfile |
7 | 7 |
|
| 8 | +import pytest |
8 | 9 | from conftest import VALID_CODE, signed_headers |
| 10 | +from fastapi.testclient import TestClient |
9 | 11 |
|
| 12 | +from prism_challenge.app import create_app |
| 13 | +from prism_challenge.config import PrismSettings |
10 | 14 | from prism_challenge.sdk.executors.docker import DockerRunResult |
11 | 15 |
|
12 | 16 |
|
| 17 | +@pytest.fixture |
| 18 | +def small_cap_client(tmp_path) -> TestClient: |
| 19 | + settings = PrismSettings( |
| 20 | + database_url=f"sqlite+aiosqlite:///{tmp_path / 'prism.sqlite3'}", |
| 21 | + shared_token="secret", |
| 22 | + allow_insecure_signatures=True, |
| 23 | + fineweb_sample_count=4, |
| 24 | + max_code_bytes=2_000, |
| 25 | + ) |
| 26 | + with TestClient(create_app(settings)) as test_client: |
| 27 | + yield test_client |
| 28 | + |
| 29 | + |
| 30 | +def _post_code(client: TestClient, code: str): |
| 31 | + payload = {"code": code, "filename": "model.py"} |
| 32 | + body = json.dumps(payload, separators=(",", ":")).encode() |
| 33 | + return client.post( |
| 34 | + "/v1/submissions", |
| 35 | + content=body, |
| 36 | + headers={**signed_headers("secret", body), "Content-Type": "application/json"}, |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +def test_size_check_accepts_just_under_cap(small_cap_client): |
| 41 | + cap = small_cap_client.app.state.settings.max_code_bytes |
| 42 | + response = _post_code(small_cap_client, "A" * (cap - 1)) |
| 43 | + assert response.status_code == 200, response.text |
| 44 | + |
| 45 | + |
| 46 | +def test_size_check_rejects_just_over_cap(small_cap_client): |
| 47 | + cap = small_cap_client.app.state.settings.max_code_bytes |
| 48 | + response = _post_code(small_cap_client, "A" * (cap + 1)) |
| 49 | + assert response.status_code == 413, response.text |
| 50 | + assert response.json()["detail"] == "submission too large" |
| 51 | + |
| 52 | + |
| 53 | + |
13 | 54 | def test_health_version_and_internal_auth(client): |
14 | 55 | assert client.get("/health").json()["slug"] == "prism" |
15 | 56 | assert "nas" in client.get("/version").json()["capabilities"] |
|
0 commit comments