File size: 2,242 Bytes
cd0c7a9 | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | """
Smoke tests for the Function Prediction endpoints.
Covers:
- POST /api/function/predict creates a job (auth required)
- GET /api/function/status/{job_id} returns status (auth required)
- Invalid PDB ID returns 422
- Missing auth returns 401
"""
import pytest
BASE_PREDICT = "/api/function/predict"
BASE_STATUS = "/api/function/status"
class TestFunctionAuth:
"""Verify auth enforcement."""
def test_no_auth_returns_401(self, client):
resp = client.post(BASE_PREDICT, json={"pdb_id": "1crn"})
assert resp.status_code == 401
def test_invalid_token_returns_401(self, client):
resp = client.post(
BASE_PREDICT,
json={"pdb_id": "1crn"},
headers={"Authorization": "Bearer bad.token.here"},
)
assert resp.status_code == 401
class TestFunctionPredict:
"""POST /api/function/predict validation."""
def test_valid_request_returns_job(self, client, auth_headers):
resp = client.post(BASE_PREDICT, json={"pdb_id": "1crn"}, headers=auth_headers)
assert resp.status_code == 200
body = resp.json()
assert "job_id" in body
assert body["status"] in ("queued", "submitted", "running")
def test_invalid_pdb_id_too_short(self, client, auth_headers):
resp = client.post(BASE_PREDICT, json={"pdb_id": "1cr"}, headers=auth_headers)
assert resp.status_code == 422
def test_invalid_pdb_id_special_chars(self, client, auth_headers):
resp = client.post(BASE_PREDICT, json={"pdb_id": "X!Y@"}, headers=auth_headers)
assert resp.status_code == 422
def test_missing_pdb_id_returns_422(self, client, auth_headers):
resp = client.post(BASE_PREDICT, json={}, headers=auth_headers)
assert resp.status_code == 422
class TestFunctionStatus:
"""GET /api/function/status/{job_id} validation."""
def test_no_auth_returns_401(self, client):
resp = client.get(f"{BASE_STATUS}/fake-id")
assert resp.status_code == 401
def test_nonexistent_job_returns_error(self, client, auth_headers):
resp = client.get(f"{BASE_STATUS}/00000000-0000-0000-0000-000000000000", headers=auth_headers)
assert resp.status_code in (404, 422, 500)
|