generated from john/python-template
document form
This commit is contained in:
+43
-2
@@ -1,7 +1,5 @@
|
||||
"""Tests for the V2 SQLModel persistence layer and relationships."""
|
||||
|
||||
from datetime import UTC
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
@@ -203,3 +201,46 @@ class TestRelationships:
|
||||
assert len(document.jobs) == 1
|
||||
assert len(document.sources) == 1
|
||||
assert len(document.document_people) == 1
|
||||
|
||||
def test_document_exposes_author_via_role_filtered_relation(self, session):
|
||||
document = _persist_document(session)
|
||||
author = _persist_person(session, full_name="Author Person")
|
||||
recipient = _persist_person(session, full_name="Recipient Person")
|
||||
|
||||
session.add(DocumentPerson(document_id=document.id, person_id=author.id, role=DocumentPersonRole.AUTHOR))
|
||||
session.add(DocumentPerson(document_id=document.id, person_id=recipient.id, role=DocumentPersonRole.RECIPIENT))
|
||||
session.commit()
|
||||
|
||||
session.refresh(document)
|
||||
assert [person.full_name for person in document.authors] == ["Author Person"]
|
||||
assert document.author is not None
|
||||
assert document.author.full_name == "Author Person"
|
||||
|
||||
def test_person_exposes_authored_documents_via_role_filtered_relation(self, session):
|
||||
authored_document = _make_document(name="Authored Doc")
|
||||
recipient_only_document = _make_document(name="Recipient Doc")
|
||||
session.add(authored_document)
|
||||
session.add(recipient_only_document)
|
||||
session.commit()
|
||||
session.refresh(authored_document)
|
||||
session.refresh(recipient_only_document)
|
||||
person = _persist_person(session, full_name="Dual Role Person")
|
||||
|
||||
session.add(
|
||||
DocumentPerson(
|
||||
document_id=authored_document.id,
|
||||
person_id=person.id,
|
||||
role=DocumentPersonRole.AUTHOR,
|
||||
)
|
||||
)
|
||||
session.add(
|
||||
DocumentPerson(
|
||||
document_id=recipient_only_document.id,
|
||||
person_id=person.id,
|
||||
role=DocumentPersonRole.RECIPIENT,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
session.refresh(person)
|
||||
assert [document.name for document in person.authored_documents] == ["Authored Doc"]
|
||||
|
||||
Reference in New Issue
Block a user