diff --git a/src/transcription/models.py b/src/transcription/models.py index 5b8d58e..f35940d 100644 --- a/src/transcription/models.py +++ b/src/transcription/models.py @@ -7,7 +7,6 @@ Three models capture the MVP lifecycle: from datetime import UTC from datetime import datetime from enum import StrEnum -from pathlib import Path from typing import Optional from uuid import UUID from uuid import uuid4 @@ -29,7 +28,7 @@ class Document(SQLModel, table=True): id: UUID = Field(default_factory=uuid4, primary_key=True) filename: str - file_path: Path + file_path: str uploaded_at: datetime = Field( default_factory=lambda: datetime.now(UTC), ) diff --git a/tests/services/test_job_service.py b/tests/services/test_job_service.py index 5a3274b..ae442fc 100644 --- a/tests/services/test_job_service.py +++ b/tests/services/test_job_service.py @@ -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."""