generated from john/python-template
pruned jobs page
This commit is contained in:
+29
-87
@@ -1,95 +1,37 @@
|
|||||||
"""Tests for transcription.ui.jobs_page."""
|
"""Tests for the jobs page route."""
|
||||||
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from transcription.models import Document, Job, Transcript
|
from transcription.ui import register_pages
|
||||||
from transcription.ui.jobs_page import fetch_job_detail, fetch_jobs
|
from transcription.ui.pages import jobs_page
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client(monkeypatch):
|
||||||
|
"""Provide a minimal app client with jobs data patched for rendering."""
|
||||||
|
|
||||||
|
async def _fetch_jobs_stub():
|
||||||
|
return []
|
||||||
|
|
||||||
|
monkeypatch.setattr(jobs_page, "fetch_jobs", _fetch_jobs_stub)
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
register_pages(app)
|
||||||
|
with TestClient(app) as test_client:
|
||||||
|
yield test_client
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
class TestJobsListBehavior:
|
class TestPageRendering:
|
||||||
"""Verify job list data and rendering helpers."""
|
"""Verify the jobs page is available and includes the main controls."""
|
||||||
|
|
||||||
def test_fetch_jobs_returns_job_view_rows(self, session, monkeypatch):
|
def test_jobs_page_renders_expected_controls(self, client):
|
||||||
"""fetch_jobs returns normalized JobView rows for UI consumption."""
|
"""GET /ui/jobs returns the page shell and jobs controls."""
|
||||||
document = Document(filename="letter.jpg", file_path="uploads/letter.jpg")
|
response = client.get("/ui/jobs")
|
||||||
session.add(document)
|
|
||||||
session.commit()
|
|
||||||
session.refresh(document)
|
|
||||||
|
|
||||||
job = Job(document_id=document.id)
|
assert response.status_code == 200
|
||||||
session.add(job)
|
assert "Transcription Jobs" in response.text
|
||||||
session.commit()
|
assert "Refresh" in response.text
|
||||||
|
assert "Back to upload" in response.text
|
||||||
class _SessionContext:
|
|
||||||
def __enter__(self):
|
|
||||||
return session
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc, tb):
|
|
||||||
return False
|
|
||||||
|
|
||||||
monkeypatch.setattr("transcription.ui.jobs_page.get_session", lambda: _SessionContext())
|
|
||||||
|
|
||||||
rows = fetch_jobs()
|
|
||||||
|
|
||||||
assert len(rows) == 1
|
|
||||||
assert rows[0].id == job.id
|
|
||||||
assert rows[0].status == "queued"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
|
||||||
class TestJobDetailBehavior:
|
|
||||||
"""Verify job detail retrieval behavior."""
|
|
||||||
|
|
||||||
def test_fetch_job_detail_returns_related_records_when_present(self, session, monkeypatch):
|
|
||||||
"""fetch_job_detail returns job, document, and transcript when available."""
|
|
||||||
document = Document(filename="typed.jpg", file_path="uploads/typed.jpg")
|
|
||||||
session.add(document)
|
|
||||||
session.commit()
|
|
||||||
session.refresh(document)
|
|
||||||
|
|
||||||
job = Job(document_id=document.id)
|
|
||||||
session.add(job)
|
|
||||||
session.commit()
|
|
||||||
session.refresh(job)
|
|
||||||
|
|
||||||
transcript = Transcript(job_id=job.id, text="Transcript text")
|
|
||||||
session.add(transcript)
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
class _SessionContext:
|
|
||||||
def __enter__(self):
|
|
||||||
return session
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc, tb):
|
|
||||||
return False
|
|
||||||
|
|
||||||
monkeypatch.setattr("transcription.ui.jobs_page.get_session", lambda: _SessionContext())
|
|
||||||
|
|
||||||
fetched_job, fetched_document, fetched_transcript = fetch_job_detail(job.id)
|
|
||||||
|
|
||||||
assert fetched_job is not None
|
|
||||||
assert fetched_document is not None
|
|
||||||
assert fetched_transcript is not None
|
|
||||||
assert fetched_job.id == job.id
|
|
||||||
assert fetched_document.id == document.id
|
|
||||||
assert fetched_transcript.job_id == job.id
|
|
||||||
|
|
||||||
def test_fetch_job_detail_returns_nones_for_missing_job(self, session, monkeypatch):
|
|
||||||
"""fetch_job_detail returns triple None when job does not exist."""
|
|
||||||
class _SessionContext:
|
|
||||||
def __enter__(self):
|
|
||||||
return session
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc, tb):
|
|
||||||
return False
|
|
||||||
|
|
||||||
monkeypatch.setattr("transcription.ui.jobs_page.get_session", lambda: _SessionContext())
|
|
||||||
|
|
||||||
fetched_job, fetched_document, fetched_transcript = fetch_job_detail(uuid4())
|
|
||||||
|
|
||||||
assert fetched_job is None
|
|
||||||
assert fetched_document is None
|
|
||||||
assert fetched_transcript is None
|
|
||||||
|
|||||||
Reference in New Issue
Block a user