V4.3 revision to Document Types

This commit is contained in:
Jim Lancaster
2026-08-15 13:29:53 -05:00
parent aed827babe
commit a78b58ff40
30 changed files with 1481 additions and 291 deletions
+6 -17
View File
@@ -11,7 +11,6 @@ from transcription.config import Settings
from transcription.db.models import Document
from transcription.db.models import DocumentPerson
from transcription.db.models import DocumentPersonRole
from transcription.db.models import DocumentType
from transcription.db.models import Job
from transcription.db.models import Person
from transcription.db.models import PersonRole
@@ -26,12 +25,13 @@ from transcription.services.people import PeopleService
@pytest.mark.asyncio
async def test_read_document_detail_allows_missing_sources(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
document_type = await service.create_document_type(label="Letter")
created = await service.create_document(
Document(
id=uuid4(),
name="detail-doc",
document_type="letter",
document_type_id=document_type.id,
)
)
@@ -41,7 +41,7 @@ async def test_read_document_detail_allows_missing_sources(default_session_facto
assert detail.sources == []
assert detail.document_type_id is not None
assert detail.document_type_ref is not None
assert detail.document_type_ref.code == "letter"
assert detail.document_type_ref.label == "Letter"
@pytest.mark.asyncio
@@ -52,7 +52,6 @@ async def test_update_document_refreshes_updated_timestamp(default_session_facto
Document(
id=uuid4(),
name="timestamp-doc",
document_type="letter",
updated_at=datetime(2000, 1, 1, tzinfo=UTC),
)
)
@@ -74,7 +73,6 @@ async def test_delete_document_blocks_when_dependencies_exist(default_session_fa
Document(
id=uuid4(),
name="blocked-delete",
document_type="record",
)
)
@@ -106,7 +104,6 @@ async def test_delete_document_succeeds_when_unlinked(default_session_factory, t
Document(
id=uuid4(),
name="free-delete",
document_type="memo",
)
)
@@ -132,7 +129,6 @@ async def test_delete_document_removes_person_links(default_session_factory, tmp
Document(
id=uuid4(),
name="person-linked-delete",
document_type="memo",
)
)
person = await people_service.create_person(Person(full_name="Linked Person"))
@@ -171,7 +167,6 @@ async def test_delete_document_removes_populated_storage_tree(default_session_fa
Document(
id=uuid4(),
name="tree-delete",
document_type="memo",
)
)
@@ -198,7 +193,6 @@ async def test_read_person_detail_loads_document_links(default_session_factory):
Document(
id=uuid4(),
name="linked-doc",
document_type="letter",
)
)
person = await people_service.create_person(Person(full_name="Linked Person"))
@@ -246,7 +240,6 @@ async def test_delete_person_removes_links_when_linked_documents_exist(default_s
Document(
id=uuid4(),
name="block-person-delete-doc",
document_type="record",
)
)
person = await service.create_person(Person(full_name="Blocked Person"))
@@ -280,16 +273,12 @@ async def test_delete_person_succeeds_when_unlinked(default_session_factory):
@pytest.mark.asyncio
async def test_create_document_reuses_existing_document_type_registry(default_session_factory):
async def test_create_document_uses_existing_document_type_registry(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
async with service._session_scope() as session:
existing = DocumentType(code="record", label="Record")
session.add(existing)
await session.commit()
await session.refresh(existing)
existing = await service.create_document_type(label="Record")
created = await service.create_document(Document(id=uuid4(), name="typed-doc", document_type="record"))
created = await service.create_document(Document(id=uuid4(), name="typed-doc", document_type_id=existing.id))
assert created.document_type_id is not None
assert created.document_type_id == existing.id