generated from john/python-template
Revamped the Documents, People, & Jobs too.
This commit is contained in:
+67
-119
@@ -1,16 +1,12 @@
|
||||
"""Tests for the people page routes."""
|
||||
"""Tests for the people page routes and action handlers."""
|
||||
|
||||
import asyncio
|
||||
from datetime import date
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from transcription.db import session_scope
|
||||
from transcription.db.models import Document
|
||||
from transcription.db.models import DocumentPerson
|
||||
from transcription.db.models import DocumentPersonRole
|
||||
from transcription.db.models import Person
|
||||
from transcription.db.models import Document, DocumentPerson, DocumentPersonRole, Person
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -27,15 +23,13 @@ class TestPeoplePageRendering:
|
||||
assert "Create new person" in response.text
|
||||
assert "No person records found in repository." in response.text
|
||||
|
||||
def test_people_page_lists_seeded_people(self, app_client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_people_page_lists_seeded_people(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_person() -> None:
|
||||
async with session_scope() as session:
|
||||
session.add(Person(full_name="Ada Lovelace", display_name="Ada"))
|
||||
await session.commit()
|
||||
|
||||
asyncio.run(_seed_person())
|
||||
async with session_scope() as session:
|
||||
session.add(Person(full_name="Ada Lovelace", display_name="Ada"))
|
||||
await session.commit()
|
||||
|
||||
response = client.get("/ui/people")
|
||||
|
||||
@@ -56,30 +50,27 @@ class TestPeoplePageRendering:
|
||||
assert "Biography" in response.text
|
||||
assert "Save person" in response.text
|
||||
|
||||
def test_person_detail_page_renders_metadata_and_empty_links(self, app_client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_person_detail_page_renders_metadata_and_empty_links(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_person() -> str:
|
||||
async with session_scope() as session:
|
||||
person = Person(
|
||||
full_name="Grace Hopper",
|
||||
display_name="Grace",
|
||||
maiden_name="Murray",
|
||||
birth_date=date(1906, 12, 9),
|
||||
birth_date_raw="1906",
|
||||
birth_place="New York",
|
||||
death_date=date(1992, 1, 1),
|
||||
death_date_raw="1992",
|
||||
death_place="Arlington",
|
||||
biography="Computer pioneer",
|
||||
portrait_path="/images/grace.jpg",
|
||||
)
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
await session.refresh(person)
|
||||
return str(person.id)
|
||||
|
||||
person_id = asyncio.run(_seed_person())
|
||||
async with session_scope() as session:
|
||||
person = Person(
|
||||
full_name="Grace Hopper",
|
||||
display_name="Grace",
|
||||
maiden_name="Murray",
|
||||
birth_date=date(1906, 12, 9),
|
||||
birth_date_raw="1906",
|
||||
birth_place="New York",
|
||||
death_date=date(1992, 1, 1),
|
||||
death_date_raw="1992",
|
||||
death_place="Arlington",
|
||||
biography="Computer pioneer",
|
||||
portrait_path="/images/grace.jpg",
|
||||
)
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
person_id = str(person.id)
|
||||
|
||||
response = client.get(f"/ui/people/{person_id}")
|
||||
|
||||
@@ -97,51 +88,44 @@ class TestPeoplePageRendering:
|
||||
assert "Created:" in response.text
|
||||
assert "Updated:" in response.text
|
||||
assert "No linked documents yet." in response.text
|
||||
assert "Link this person from a Document workflow." in response.text
|
||||
|
||||
def test_person_detail_page_resolves_relative_portrait_path_to_uploads_mount(self, app_client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_person_detail_page_resolves_relative_portrait_path(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_person() -> str:
|
||||
async with session_scope() as session:
|
||||
person = Person(
|
||||
full_name="Portrait Person",
|
||||
portrait_path="portraits/person/seeded.png",
|
||||
)
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
await session.refresh(person)
|
||||
return str(person.id)
|
||||
async with session_scope() as session:
|
||||
person = Person(
|
||||
full_name="Portrait Person",
|
||||
portrait_path="portraits/person/seeded.png",
|
||||
)
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
person_id = str(person.id)
|
||||
|
||||
person_id = asyncio.run(_seed_person())
|
||||
response = client.get(f"/ui/people/{person_id}")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "/uploads/portraits/person/seeded.png" in response.text
|
||||
|
||||
def test_person_detail_page_renders_linked_documents(self, app_client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_person_detail_page_renders_linked_documents(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_links() -> str:
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Linked Person")
|
||||
document = Document(name="Linked Document", document_type="letter")
|
||||
session.add(person)
|
||||
session.add(document)
|
||||
await session.flush()
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Linked Person")
|
||||
document = Document(name="Linked Document", document_type="letter")
|
||||
session.add_all([person, document])
|
||||
await session.flush()
|
||||
|
||||
session.add(
|
||||
DocumentPerson(
|
||||
document_id=document.id,
|
||||
person_id=person.id,
|
||||
role=DocumentPersonRole.AUTHOR,
|
||||
)
|
||||
session.add(
|
||||
DocumentPerson(
|
||||
document_id=document.id,
|
||||
person_id=person.id,
|
||||
role=DocumentPersonRole.AUTHOR,
|
||||
)
|
||||
await session.commit()
|
||||
await session.refresh(person)
|
||||
return str(person.id)
|
||||
|
||||
person_id = asyncio.run(_seed_links())
|
||||
)
|
||||
await session.commit()
|
||||
person_id = str(person.id)
|
||||
|
||||
response = client.get(f"/ui/people/{person_id}")
|
||||
|
||||
@@ -165,73 +149,37 @@ class TestPeoplePageRendering:
|
||||
assert response.status_code == 200
|
||||
assert "Person not found" in response.text
|
||||
|
||||
def test_person_edit_page_renders_expected_fields(self, app_client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_person_edit_page_renders_expected_fields(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_person() -> str:
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Editable Person", display_name="EP")
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
await session.refresh(person)
|
||||
return str(person.id)
|
||||
|
||||
person_id = asyncio.run(_seed_person())
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Editable Person", display_name="EP")
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
person_id = str(person.id)
|
||||
|
||||
response = client.get(f"/ui/people/{person_id}/edit")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "Edit Person Record" in response.text
|
||||
assert "Full name is required." in response.text
|
||||
assert "Full name" in response.text
|
||||
assert "Editable Person" in response.text
|
||||
assert "Save changes" in response.text
|
||||
|
||||
def test_person_delete_page_shows_confirmation_when_unlinked(self, app_client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_person_delete_page_shows_confirmation_when_unlinked(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_person() -> str:
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Safe Delete")
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
await session.refresh(person)
|
||||
return str(person.id)
|
||||
|
||||
person_id = asyncio.run(_seed_person())
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Safe Delete")
|
||||
session.add(person)
|
||||
await session.commit()
|
||||
person_id = str(person.id)
|
||||
|
||||
response = client.get(f"/ui/people/{person_id}/delete")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "Delete Person Record" in response.text
|
||||
assert "This action permanently deletes the person record." in response.text
|
||||
assert "Delete person permanently" in response.text
|
||||
|
||||
def test_person_delete_page_warns_links_will_be_removed_when_linked_documents_exist(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async def _seed_links() -> str:
|
||||
async with session_scope() as session:
|
||||
person = Person(full_name="Blocked Delete")
|
||||
document = Document(name="Linked Document", document_type="record")
|
||||
session.add(person)
|
||||
session.add(document)
|
||||
await session.flush()
|
||||
|
||||
session.add(
|
||||
DocumentPerson(
|
||||
document_id=document.id,
|
||||
person_id=person.id,
|
||||
role=DocumentPersonRole.AUTHOR,
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
await session.refresh(person)
|
||||
return str(person.id)
|
||||
|
||||
person_id = asyncio.run(_seed_links())
|
||||
|
||||
response = client.get(f"/ui/people/{person_id}/delete")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "This will also remove 1 linked document relationship(s)." in response.text
|
||||
assert "Delete person permanently" in response.text
|
||||
assert "Delete person permanently" in response.text
|
||||
Reference in New Issue
Block a user