generated from john/python-template
V4.3 revision to Document Types
This commit is contained in:
@@ -4,11 +4,13 @@ from datetime import date
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlmodel import select
|
||||
|
||||
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 DocumentType
|
||||
from transcription.db.models import Job
|
||||
from transcription.db.models import Person
|
||||
from transcription.db.models import Source
|
||||
@@ -20,13 +22,14 @@ from transcription.db.models import Source
|
||||
async def seed_person_and_document():
|
||||
"""Seed a Person and Document linked by DocumentPerson role."""
|
||||
async with session_scope() as session:
|
||||
letter_type = (await session.exec(select(DocumentType).where(DocumentType.label == "Letter"))).one()
|
||||
person = Person(full_name="Zenna Cochran")
|
||||
session.add(person)
|
||||
await session.flush()
|
||||
|
||||
doc = Document(
|
||||
name="Letter from Hig",
|
||||
document_type="letter",
|
||||
document_type_id=letter_type.id,
|
||||
archive_identifier="ZC-1924-001",
|
||||
)
|
||||
session.add(doc)
|
||||
@@ -63,7 +66,12 @@ class TestDocumentsPageRendering:
|
||||
_, client = app_client
|
||||
|
||||
async with session_scope() as session:
|
||||
doc = Document(name="1924 Postcard", document_type="postcard", archive_identifier="PC-001")
|
||||
postcard_type = (await session.exec(select(DocumentType).where(DocumentType.label == "Postcard"))).one()
|
||||
doc = Document(
|
||||
name="1924 Postcard",
|
||||
document_type_id=postcard_type.id,
|
||||
archive_identifier="PC-001",
|
||||
)
|
||||
session.add(doc)
|
||||
await session.commit()
|
||||
|
||||
@@ -71,7 +79,7 @@ class TestDocumentsPageRendering:
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "1924 Postcard" in response.text
|
||||
assert "postcard" in response.text
|
||||
assert "Postcard" in response.text
|
||||
assert "PC-001" in response.text
|
||||
assert "Document Date" in response.text
|
||||
assert "Author" in response.text
|
||||
@@ -106,9 +114,7 @@ class TestDocumentsPageRendering:
|
||||
assert "Hig - Albert Edward Higgins (1885)" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_document_detail_page_renders_bento_grid_and_metadata(
|
||||
self, app_client, seed_person_and_document
|
||||
):
|
||||
async def test_document_detail_page_renders_bento_grid_and_metadata(self, app_client, seed_person_and_document):
|
||||
_, client = app_client
|
||||
doc_id, _ = seed_person_and_document
|
||||
|
||||
@@ -143,9 +149,7 @@ class TestDocumentsPageRendering:
|
||||
assert f"Job ID: {job_id}" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_document_edit_page_prefills_existing_values(
|
||||
self, app_client, seed_person_and_document
|
||||
):
|
||||
async def test_document_edit_page_prefills_existing_values(self, app_client, seed_person_and_document):
|
||||
_, client = app_client
|
||||
doc_id, _ = seed_person_and_document
|
||||
|
||||
@@ -157,9 +161,7 @@ class TestDocumentsPageRendering:
|
||||
assert "ZC-1924-001" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_document_delete_page_blocks_deletion_when_dependencies_exist(
|
||||
self, app_client
|
||||
):
|
||||
async def test_document_delete_page_blocks_deletion_when_dependencies_exist(self, app_client):
|
||||
_, client = app_client
|
||||
|
||||
async with session_scope() as session:
|
||||
|
||||
@@ -84,9 +84,7 @@ class TestJobsPageRendering:
|
||||
assert "Preselected Journal Entry" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_job_detail_page_renders_logistics_and_links(
|
||||
self, app_client, seed_document_with_unlinked_job
|
||||
):
|
||||
async def test_job_detail_page_renders_logistics_and_links(self, app_client, seed_document_with_unlinked_job):
|
||||
_, client = app_client
|
||||
_, job_id = seed_document_with_unlinked_job
|
||||
|
||||
@@ -102,9 +100,7 @@ class TestJobsPageRendering:
|
||||
assert "updates automatically while the job is active" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_job_cancel_page_renders_confirmation(
|
||||
self, app_client, seed_document_with_unlinked_job
|
||||
):
|
||||
async def test_job_cancel_page_renders_confirmation(self, app_client, seed_document_with_unlinked_job):
|
||||
_, client = app_client
|
||||
_, job_id = seed_document_with_unlinked_job
|
||||
|
||||
@@ -116,9 +112,7 @@ class TestJobsPageRendering:
|
||||
assert "Cancel job" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_job_resubmit_page_renders_counts(
|
||||
self, app_client, seed_job
|
||||
):
|
||||
async def test_job_resubmit_page_renders_counts(self, app_client, seed_job):
|
||||
_, client = app_client
|
||||
job_id = await seed_job(
|
||||
filename="failed-resubmit.png",
|
||||
|
||||
@@ -31,6 +31,7 @@ class TestNavigationAndMounts:
|
||||
"/ui/people",
|
||||
"/ui/sources",
|
||||
"/ui/jobs",
|
||||
"/ui/settings",
|
||||
],
|
||||
)
|
||||
def test_registered_pages_render_successfully(self, app_client, route_path: str):
|
||||
@@ -39,4 +40,4 @@ class TestNavigationAndMounts:
|
||||
response = client.get(route_path)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "html" in response.headers.get("content-type", "").lower()
|
||||
assert "html" in response.headers.get("content-type", "").lower()
|
||||
|
||||
@@ -16,9 +16,11 @@ class TestPageRegistration:
|
||||
people_response = client.get("/ui/people")
|
||||
sources_response = client.get("/ui/sources")
|
||||
jobs_response = client.get("/ui/jobs")
|
||||
settings_response = client.get("/ui/settings")
|
||||
|
||||
assert homepage_response.status_code == 200
|
||||
assert documents_response.status_code == 200
|
||||
assert people_response.status_code == 200
|
||||
assert sources_response.status_code == 200
|
||||
assert jobs_response.status_code == 200
|
||||
assert settings_response.status_code == 200
|
||||
|
||||
@@ -48,9 +48,7 @@ class TestSourceModelProperties:
|
||||
async with session_scope() as session:
|
||||
job = await session.get(Job, job_id)
|
||||
assert job is not None
|
||||
source = (
|
||||
await session.exec(select(Source).where(Source.document_id == job.document_id))
|
||||
).first()
|
||||
source = (await session.exec(select(Source).where(Source.document_id == job.document_id))).first()
|
||||
assert source is not None
|
||||
|
||||
# Validate computed properties
|
||||
@@ -159,9 +157,7 @@ class TestSourcesPageRendering:
|
||||
assert "job-page.png" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sources_page_job_context_shows_job_source_status_and_error_detail(
|
||||
self, app_client, seed_job
|
||||
):
|
||||
async def test_sources_page_job_context_shows_job_source_status_and_error_detail(self, app_client, seed_job):
|
||||
_, client = app_client
|
||||
job_id = await seed_job(
|
||||
filename="job-failed-page.png",
|
||||
@@ -178,17 +174,9 @@ class TestSourcesPageRendering:
|
||||
assert "Provider timed out" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_source_detail_page_renders_preview_and_revision_box(
|
||||
self, app_client, seed_job
|
||||
):
|
||||
async def test_source_detail_page_renders_preview_and_revision_box(self, app_client, seed_job):
|
||||
_, client = app_client
|
||||
fixture_path = (
|
||||
Path(__file__).resolve().parents[1]
|
||||
/ "fixtures"
|
||||
/ "images"
|
||||
/ "valid"
|
||||
/ "small_png.png"
|
||||
)
|
||||
fixture_path = Path(__file__).resolve().parents[1] / "fixtures" / "images" / "valid" / "small_png.png"
|
||||
job_id = await seed_job(
|
||||
filename="detail-source.png",
|
||||
transcription_text="original transcription text",
|
||||
@@ -201,9 +189,7 @@ class TestSourcesPageRendering:
|
||||
async with session_scope() as session:
|
||||
job = await session.get(Job, job_id)
|
||||
assert job is not None
|
||||
source = (
|
||||
await session.exec(select(Source).where(Source.document_id == job.document_id))
|
||||
).first()
|
||||
source = (await session.exec(select(Source).where(Source.document_id == job.document_id))).first()
|
||||
assert source is not None
|
||||
source_id = str(source.id)
|
||||
|
||||
@@ -232,9 +218,7 @@ class TestSourcesPageRendering:
|
||||
async with session_scope(session_factory=app.state.runtime.session_factory) as session:
|
||||
job = await session.get(Job, job_id)
|
||||
assert job is not None
|
||||
source = (
|
||||
await session.exec(select(Source).where(Source.document_id == job.document_id))
|
||||
).first()
|
||||
source = (await session.exec(select(Source).where(Source.document_id == job.document_id))).first()
|
||||
assert source is not None
|
||||
source_id = source.id
|
||||
|
||||
@@ -268,18 +252,14 @@ class TestSourcesPageRendering:
|
||||
assert "Derived Artifacts" in response.text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_source_delete_page_blocks_when_source_is_job_linked(
|
||||
self, app_client, seed_job
|
||||
):
|
||||
async def test_source_delete_page_blocks_when_source_is_job_linked(self, app_client, seed_job):
|
||||
_, client = app_client
|
||||
job_id = await seed_job(filename="linked-source.png", transcription_text="linked text")
|
||||
|
||||
async with session_scope() as session:
|
||||
job = await session.get(Job, job_id)
|
||||
assert job is not None
|
||||
source = (
|
||||
await session.exec(select(Source).where(Source.document_id == job.document_id))
|
||||
).first()
|
||||
source = (await session.exec(select(Source).where(Source.document_id == job.document_id))).first()
|
||||
assert source is not None
|
||||
source_id = str(source.id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user