Skip to content

Commit d95d730

Browse files
eprifticlaude
andcommitted
Fix test_export_pending_job_returns_400 — create pending job directly in DB
The SQLite locking fix caused mock jobs to complete instantly, so the export-pending test was hitting an already-completed job. Now creates a pending job directly without triggering the background task. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5f320e1 commit d95d730

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎backend/tests/test_api.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,15 +2532,19 @@ class TestErrorRecovery:
25322532
"""Tests for error handling and edge cases."""
25332533

25342534
@pytest.mark.asyncio
2535-
async def test_export_pending_job_returns_400(self, auth_client):
2535+
async def test_export_pending_job_returns_400(self, auth_client, db_session):
25362536
"""Exporting results of a non-completed job should fail."""
2537+
from app.models.db_models import Job
2538+
25372539
pid, x_fid, y_fid = await _create_project_with_datasets(auth_client)
2538-
# Create a job but don't mark it as completed
2539-
job_id = await _run_mock_analysis(auth_client, pid, x_fid, y_fid)
2540+
# Create a pending job directly in DB (no background task)
2541+
job = Job(project_id=pid, user_id="test", status="pending", config={})
2542+
db_session.add(job)
2543+
await db_session.commit()
25402544

2541-
# Try to export — job is pending/running, not completed
2545+
# Try to export — job is pending, not completed
25422546
resp = await auth_client.get(
2543-
f"/api/export/{pid}/jobs/{job_id}/csv",
2547+
f"/api/export/{pid}/jobs/{job.id}/csv",
25442548
params={"section": "best_model"},
25452549
)
25462550
assert resp.status_code == 400

0 commit comments

Comments
 (0)