generated from john/python-template
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
"""Phase 6 verification that modification timestamps advance automatically.
|
|
|
|
Covers the `onupdate` change: `updated_at` / `date_updated` are now maintained
|
|
by the ORM column default rather than by hand at each call site, so update paths
|
|
that previously forgot to set them no longer report a stale timestamp.
|
|
"""
|
|
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from transcription.db.models import Document
|
|
from transcription.db.models import Job
|
|
from transcription.db.models import JobStatus
|
|
from transcription.db.models import Person
|
|
from transcription.services.documents import DocumentService
|
|
from transcription.services.jobs import JobService
|
|
from transcription.services.people import PeopleService
|
|
from transcription.services.people import PersonRoleRegistry
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_document_update_advances_updated_at(default_session_factory):
|
|
documents = DocumentService(session_factory=default_session_factory)
|
|
document = await documents.create_document(Document(id=uuid4(), name="timestamps"))
|
|
original = document.updated_at
|
|
|
|
document.name = "timestamps renamed"
|
|
updated = await documents.update_document(document)
|
|
|
|
assert updated.updated_at > original
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_person_update_advances_updated_at(default_session_factory):
|
|
people = PeopleService(session_factory=default_session_factory)
|
|
person = await people.create_person(Person(given_names="Grace", last_name="Hopper"))
|
|
original = person.updated_at
|
|
|
|
person.given_names = "Rear Adm. Grace"
|
|
person.last_name = "Hopper"
|
|
updated = await people.update_person(person)
|
|
|
|
assert updated.updated_at > original
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_registry_update_advances_updated_at(default_session_factory):
|
|
roles = PersonRoleRegistry(session_factory=default_session_factory)
|
|
role = await roles.create_entry(label="Witness")
|
|
original = role.updated_at
|
|
|
|
updated = await roles.update_entry(role.id, label="Chief Witness", is_active=True)
|
|
|
|
assert updated.updated_at > original
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_job_status_update_advances_date_updated(default_session_factory):
|
|
documents = DocumentService(session_factory=default_session_factory)
|
|
jobs = JobService(session_factory=default_session_factory)
|
|
|
|
document = await documents.create_document(Document(id=uuid4(), name="job-timestamps"))
|
|
job = await jobs.create_job(Job(document_id=document.id))
|
|
original = job.date_updated
|
|
|
|
updated = await jobs.update_job_state(job_id=job.id, status=JobStatus.PROCESSING)
|
|
|
|
assert updated.date_updated > original
|