Spaces:
Running
Running
Download tests/test_intervention_pipeline.py from Deign86/mathpulse-api-v3test: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/Deign86/mathpulse-api-v3test/resolve/main/tests/test_intervention_pipeline.py
- Command line
-
hf download hf://spaces/Deign86/mathpulse-api-v3test/tests/test_intervention_pipeline.py
-
curl -L -o test_intervention_pipeline.py https://huggingface.co/spaces/Deign86/mathpulse-api-v3test/resolve/main/tests/test_intervention_pipeline.py
2.38 kB
| """Intervention and student intelligence pipeline authorization regressions.""" | |
| from unittest.mock import patch | |
| from fastapi.testclient import TestClient | |
| from pydantic import ValidationError | |
| import pytest | |
| from main import app | |
| from routes.intervention_routes import CompleteStepRequest, GenerateRequest | |
| from routes.pipeline_routes import PipelineEventPayload | |
| pytestmark = pytest.mark.usefixtures("isolated_mock_student_auth") | |
| client = TestClient(app) | |
| def test_intervention_request_models_accept_happy_values_and_default_metrics(): | |
| assert GenerateRequest(student_id="s1").student_id == "s1" | |
| completion = CompleteStepRequest() | |
| assert completion.score == 0.0 and completion.time_spent_minutes == 0 | |
| def test_intervention_step_requires_authentication_and_student_cannot_recompute(): | |
| assert client.post("/api/intervention/s1/step/1/complete", json={}).status_code == 401 | |
| response = client.post( | |
| "/api/pipeline/profile/s2/recompute", | |
| headers={"Authorization": "Bearer mock_token_student-1"}, | |
| ) | |
| assert response.status_code == 403 | |
| def test_pipeline_event_happy_path_accepts_own_event(): | |
| response = client.post( | |
| "/api/pipeline/event", | |
| headers={"Authorization": "Bearer mock_token_student-1"}, | |
| json={"student_id": "student-1", "event_type": "diagnostic", "event_data": {}, "occurred_at": "2026-01-01T00:00:00Z"}, | |
| ) | |
| assert response.status_code == 202 | |
| assert response.json()["status"] == "accepted" | |
| def test_pipeline_blocks_cross_student_event_and_rejects_unknown_event_type(): | |
| response = client.post( | |
| "/api/pipeline/event", | |
| headers={"Authorization": "Bearer mock_token_student-1"}, | |
| json={"student_id": "student-2", "event_type": "quiz", "occurred_at": "2026-01-01T00:00:00Z"}, | |
| ) | |
| assert response.status_code == 403 | |
| with pytest.raises(ValidationError): | |
| PipelineEventPayload.model_validate({"student_id": "student-1", "event_type": "unknown", "occurred_at": "now"}) | |
| def test_pipeline_recompute_requires_staff_and_intervention_bad_step_is_rejected(): | |
| assert client.post("/api/pipeline/profile/s1/recompute").status_code == 401 | |
| response = client.post( | |
| "/api/intervention/s1/step/not-an-integer/complete", | |
| headers={"Authorization": "Bearer mock_token_student-1"}, | |
| json={}, | |
| ) | |
| assert response.status_code == 422 | |