job service tests

This commit is contained in:
John Lancaster
2026-06-27 19:29:51 -05:00
parent d3ffb01e93
commit e6f12fa993
2 changed files with 25 additions and 16 deletions
+24 -14
View File
@@ -2,20 +2,13 @@ from uuid import uuid4
import pytest
from transcription.config import Settings
from transcription.db.runtime import get_session_factory
from transcription.models import Document
from transcription.models import Job
from transcription.services.documents import DocumentService
from transcription.services.jobs import JobService
from transcription.services.jobs import JobStatus
@pytest.fixture
def job_service(default_settings: Settings) -> JobService:
"""Provide a JobService instance for testing."""
session_factory = get_session_factory(settings=default_settings)
return JobService(session_factory=session_factory)
class TestJobService:
class TestBasicCRUD:
@pytest.mark.asyncio
@@ -31,6 +24,23 @@ class TestJobService:
for _ in range(10):
await job_service.create_job(job=fake_job_factory(), session=session)
@pytest.mark.asyncio
async def test_backpropagation(self, job_service: JobService, document_service: DocumentService):
"""Test that creating a job backpropagates to the related document."""
doc_id = uuid4()
document = Document(
id=doc_id,
filename="test.txt",
file_path="/path/to/test.txt",
)
await document_service.create_document(document=document)
job = Job(document_id=doc_id)
await job_service.create_job(job=job)
read_job = await job_service.read_job(job_id=job.id)
assert isinstance(read_job.document, Document)
assert read_job.document.id == document.id
@pytest.mark.asyncio
async def test_reading_job(self, job_service: JobService):
"""Test reading a job."""
@@ -67,12 +77,12 @@ class TestJobService:
@pytest.mark.asyncio
async def test_list_jobs(self, job_service: JobService):
"""Test listing jobs."""
n = 5
for _ in range(n):
await job_service.create_job(job=Job(document_id=uuid4()))
jobs = await job_service.list_jobs()
assert len(jobs) == n
@pytest.mark.asyncio
async def test_mark_job_status(self, job_service: JobService):
"""Test marking a job with a new status."""
class TestMultipleOperations:
@pytest.mark.asyncio
async def test_multiple_operations(self, job_service: JobService):
"""Test multiple operations on jobs."""