generated from john/python-template
This commit is contained in:
@@ -5,13 +5,16 @@ from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from sqlmodel import select
|
||||
|
||||
from transcription.config import Settings
|
||||
from transcription.db.models import Document
|
||||
from transcription.db.models import DocumentPerson
|
||||
from transcription.db.models import DocumentTag
|
||||
from transcription.db.models import Job
|
||||
from transcription.db.models import Person
|
||||
from transcription.db.models import Source
|
||||
from transcription.db.models import Tag
|
||||
from transcription.services.documents import DocumentDeleteBlockedError
|
||||
from transcription.services.documents import DocumentError
|
||||
from transcription.services.documents import DocumentService
|
||||
@@ -311,3 +314,26 @@ async def test_update_document_person_changes_role_id(default_session_factory):
|
||||
)
|
||||
|
||||
assert updated.role_id == recipient_role.id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_document_tags_by_labels_creates_and_replaces_tags(default_session_factory):
|
||||
documents = DocumentService(session_factory=default_session_factory)
|
||||
document = await documents.create_document(Document(id=uuid4(), name="tagged-doc"))
|
||||
|
||||
await documents.sync_document_tags_by_labels(document_id=document.id, labels=["Family", "Census"])
|
||||
await documents.sync_document_tags_by_labels(document_id=document.id, labels=["Census", "Research"])
|
||||
|
||||
async with documents._session_scope() as session:
|
||||
links = (await session.exec(select(DocumentTag).where(DocumentTag.document_id == document.id))).all()
|
||||
tags = (await session.exec(select(Tag))).all()
|
||||
|
||||
assert len(links) == 2
|
||||
linked_ids = {link.tag_id for link in links}
|
||||
linked_labels = {tag.label for tag in tags if tag.id in linked_ids}
|
||||
assert linked_labels == {"Census", "Research"}
|
||||
|
||||
listed = await documents.list_documents()
|
||||
assert len(listed) == 1
|
||||
listed_labels = {link.tag_ref.label for link in listed[0].document_tags if link.tag_ref is not None}
|
||||
assert listed_labels == {"Census", "Research"}
|
||||
|
||||
@@ -31,6 +31,7 @@ async def test_create_document_with_people_rolls_back_on_invalid_person(default_
|
||||
await create_document_with_people(
|
||||
document=Document(name="Must roll back"),
|
||||
links=[DocumentPersonInput(person_id=uuid4(), role_id=role.id)],
|
||||
tag_labels=[],
|
||||
documents=documents,
|
||||
people=people,
|
||||
)
|
||||
@@ -48,6 +49,7 @@ async def test_update_document_with_people_rolls_back_document_and_links(default
|
||||
document = await create_document_with_people(
|
||||
document=Document(name="Original name"),
|
||||
links=[DocumentPersonInput(person_id=person.id, role_id=role.id)],
|
||||
tag_labels=[],
|
||||
documents=documents,
|
||||
people=people,
|
||||
)
|
||||
@@ -63,6 +65,7 @@ async def test_update_document_with_people_rolls_back_document_and_links(default
|
||||
await update_document_with_people(
|
||||
document=candidate,
|
||||
links=[DocumentPersonInput(person_id=person.id, role_id=inactive.id)],
|
||||
tag_labels=[],
|
||||
documents=documents,
|
||||
people=people,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user