Open source video conferencing app powered by LiveKit. Built with Django and React.
✅(summary) add tests for the task endpoint
lebaudantoinea27def119ced
diff --git a/src/summary/tests/api/test_api_tasks.py b/src/summary/tests/api/test_api_tasks.pynew file mode 100644index 00000000..9492bf95--- /dev/null+++ b/src/summary/tests/api/test_api_tasks.py@@ -0,0 +1,88 @@+"""Integration tests for the API tasks endpoints."""++# tests/unit/test_api_tasks.py+from unittest.mock import MagicMock, patch+++class TestTasks:+ """Tests for the /tasks endpoint."""++ @patch(+ "summary.api.route.tasks.process_audio_transcribe_summarize_v2.apply_async",+ return_value=MagicMock(id="task-id-abc"),+ )+ @patch("summary.api.route.tasks.time.time", return_value=1735725600.0)+ def test_create_task_returns_task_id(self, mock_time, mock_apply_async, client):+ """POST /tasks/ with valid payload returns id and dispatches Celery task."""+ response = client.post(+ "api/v1/tasks/",+ headers={"Authorization": "Bearer test-api-token"},+ json={+ "owner_id": "owner-123",+ "filename": "recording.mp4",+ "email": "[email protected]",+ "sub": "sub-123",+ "room": "room-abc",+ "recording_date": "2026-01-01",+ "recording_time": "10:00:00",+ "language": None,+ "download_link": "http://example.com/file.mp4",+ },+ )++ assert response.status_code == 200+ assert response.json() == {"id": "task-id-abc", "message": "Task created"}++ args = mock_apply_async.call_args.kwargs["args"]+ assert args == [+ "owner-123", # owner_id+ "recording.mp4", # filename+ "[email protected]", # email+ "sub-123", # sub+ 1735725600.0, # frozen time+ "room-abc", # room+ "2026-01-01", # recording_date+ "10:00:00", # recording_time+ None, # language+ "http://example.com/file.mp4", # download_link+ None, # context_language+ ]++ def test_create_task_invalid_language(self, client):+ """POST /tasks/ with an unsupported language returns 422."""+ payload = {"language": "klingon"}+ response = client.post(+ "/api/v1/tasks/",+ headers={"Authorization": "Bearer test-api-token"},+ json=payload,+ )++ assert response.status_code == 422++ @patch(+ "summary.api.route.tasks.AsyncResult",+ return_value=MagicMock(status="PENDING"),+ )+ def test_get_task_status_pending(self, mock_result, client):+ """GET /tasks/{id} returns PENDING status when the task has not started yet."""+ response = client.get(+ "/api/v1/tasks/task-id-abc",+ headers={"Authorization": "Bearer test-api-token"},+ )++ assert response.status_code == 200+ assert response.json() == {"id": "task-id-abc", "status": "PENDING"}++ @patch(+ "summary.api.route.tasks.AsyncResult",+ return_value=MagicMock(status="SUCCESS"),+ )+ def test_get_task_status_success(self, mock_result, client):+ """GET /tasks/{id} returns SUCCESS status when the task has completed."""+ response = client.get(+ "/api/v1/tasks/task-id-abc",+ headers={"Authorization": "Bearer test-api-token"},+ )++ assert response.status_code == 200+ assert response.json()["status"] == "SUCCESS"diff --git a/src/summary/tests/conftest.py b/src/summary/tests/conftest.pyindex cbce00b9..e002c46e 100644--- a/src/summary/tests/conftest.py+++ b/src/summary/tests/conftest.py@@ -2,11 +2,23 @@import pytestfrom fastapi.testclient import TestClient+from pydantic import SecretStr+from summary.core.config import Settings, get_settingsfrom summary.main import app+def get_settings_override():+ """Return settings for tests."""+ return Settings(+ app_api_token=SecretStr("test-api-token"),+ )++@pytest.fixture()def client():- """Provide a FastAPI TestClient for integration tests."""- return TestClient(app)+ """Provide a FastAPI TestClient for tests."""+ client = TestClient(app)+ app.dependency_overrides[get_settings] = get_settings_override++ return client