generated from john/python-template
+42
@@ -0,0 +1,42 @@
|
||||
0 HEAD
|
||||
1 SOUR getmyancestors
|
||||
1 GEDC
|
||||
2 VERS 5.5.1
|
||||
1 CHAR UTF-8
|
||||
0 @I1@ INDI
|
||||
1 NAME John /Doe/
|
||||
1 REFN KWC1-ABC
|
||||
2 TYPE FSFTID
|
||||
1 BIRT
|
||||
2 DATE 1 JAN 1900
|
||||
2 PLAC Springfield, Illinois
|
||||
2 SOUR Birth Register
|
||||
3 PAGE p. 12
|
||||
1 DEAT
|
||||
2 DATE 5 FEB 1970
|
||||
2 PLAC Shelbyville, Illinois
|
||||
2 SOUR Death Certificate
|
||||
3 TEXT County archive
|
||||
0 @I2@ INDI
|
||||
1 NAME Jane /Smith/
|
||||
1 _FSFTID LMN2-XYZ
|
||||
1 BIRT
|
||||
2 DATE 12 MAR 1905
|
||||
2 PLAC Capital City, Illinois
|
||||
0 @I3@ INDI
|
||||
1 NAME Child /Doe/
|
||||
1 REFN CHD3-123
|
||||
2 TYPE FSFTID
|
||||
0 @F1@ FAM
|
||||
1 REFN FAM-001
|
||||
2 TYPE FSFTID
|
||||
1 HUSB @I1@
|
||||
1 WIFE @I2@
|
||||
1 CHIL @I3@
|
||||
2 PEDI adopted
|
||||
1 MARR
|
||||
2 DATE 4 APR 1925
|
||||
2 PLAC Springfield, Illinois
|
||||
2 SOUR Marriage License
|
||||
3 PAGE Book 9
|
||||
0 TRLR
|
||||
@@ -0,0 +1,69 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from sqlmodel import select
|
||||
|
||||
from transcription.db.models import GenealogyCitation
|
||||
from transcription.db.models import GenealogyFamily
|
||||
from transcription.db.models import GenealogyFamilyChild
|
||||
from transcription.db.models import GenealogyPerson
|
||||
from transcription.services.gedcom_import import import_gedcom_file
|
||||
from transcription.services.gedcom_import import parse_gedcom
|
||||
|
||||
_FIXTURE_PATH = Path(__file__).resolve().parents[1] / "fixtures" / "gedcom" / "sample_familysearch.ged"
|
||||
|
||||
|
||||
def test_parse_gedcom_extracts_people_families_and_citations():
|
||||
parsed = parse_gedcom(file_path=_FIXTURE_PATH)
|
||||
|
||||
assert len(parsed.people) == 3
|
||||
john = next(person for person in parsed.people if person.fs_id == "KWC1-ABC")
|
||||
assert john.full_name == "John Doe"
|
||||
assert john.birth_date == date(1900, 1, 1)
|
||||
assert john.birth_place == "Springfield, Illinois"
|
||||
assert john.death_date == date(1970, 2, 5)
|
||||
assert len(john.citations) == 2
|
||||
assert "Birth Register" in john.citations[0].raw_citation_text
|
||||
|
||||
assert len(parsed.families) == 1
|
||||
family = parsed.families[0]
|
||||
assert family.fs_family_id == "FAM-001"
|
||||
assert family.marriage_date == date(1925, 4, 4)
|
||||
assert family.marriage_place == "Springfield, Illinois"
|
||||
assert len(family.children) == 1
|
||||
assert family.children[0].relationship_type == "adopted"
|
||||
assert len(family.citations) == 1
|
||||
assert "Marriage License" in family.citations[0].raw_citation_text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_import_gedcom_file_is_idempotent(default_session_factory):
|
||||
async with default_session_factory() as session:
|
||||
first = await import_gedcom_file(session=session, file_path=_FIXTURE_PATH)
|
||||
async with default_session_factory() as session:
|
||||
second = await import_gedcom_file(session=session, file_path=_FIXTURE_PATH)
|
||||
async with default_session_factory() as session:
|
||||
people = (await session.exec(select(GenealogyPerson))).all()
|
||||
families = (await session.exec(select(GenealogyFamily))).all()
|
||||
children = (await session.exec(select(GenealogyFamilyChild))).all()
|
||||
citations = (await session.exec(select(GenealogyCitation))).all()
|
||||
|
||||
assert first.new_people == 3
|
||||
assert first.new_families == 1
|
||||
assert first.family_children == 1
|
||||
assert first.citations == 3
|
||||
|
||||
assert second.new_people == 0
|
||||
assert second.updated_people == 0
|
||||
assert second.new_families == 0
|
||||
assert second.updated_families == 0
|
||||
assert second.family_children == 1
|
||||
assert second.citations == 3
|
||||
|
||||
assert len(people) == 3
|
||||
assert len(families) == 1
|
||||
assert len(children) == 1
|
||||
assert len(citations) == 3
|
||||
@@ -22,11 +22,13 @@ async def test_enqueue_and_list_runs(default_session_factory, default_settings):
|
||||
|
||||
first = await service.enqueue_run(job_type=MaintenanceJobType.BACKUP, triggered_by="test")
|
||||
second = await service.enqueue_run(job_type=MaintenanceJobType.STORAGE_RECONCILIATION, triggered_by="test")
|
||||
third = await service.enqueue_run(job_type=MaintenanceJobType.GEDCOM_IMPORT, triggered_by="test")
|
||||
runs = await service.list_runs(limit=10)
|
||||
|
||||
assert len(runs) == 2
|
||||
assert runs[0].id == second.id
|
||||
assert runs[1].id == first.id
|
||||
assert len(runs) == 3
|
||||
assert runs[0].id == third.id
|
||||
assert runs[1].id == second.id
|
||||
assert runs[2].id == first.id
|
||||
assert runs[0].status == MaintenanceRunStatus.QUEUED
|
||||
|
||||
|
||||
@@ -72,3 +74,20 @@ async def test_list_runs_raises_when_table_is_missing(default_session_factory, d
|
||||
with pytest.raises(MaintenanceError) as exc:
|
||||
await service.list_runs(limit=10)
|
||||
assert exc.value.category == ErrorCategory.INFRA_PERSISTENT
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_execute_run_dispatches_gedcom_import(default_session_factory, default_settings, monkeypatch):
|
||||
service = MaintenanceService(session_factory=default_session_factory, settings=default_settings)
|
||||
run = await service.enqueue_run(job_type=MaintenanceJobType.GEDCOM_IMPORT, triggered_by="test")
|
||||
|
||||
async def _fake_gedcom_import():
|
||||
return MaintenanceExecution(
|
||||
status=MaintenanceRunStatus.SUCCEEDED,
|
||||
summary="GEDCOM imported",
|
||||
output="ok",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(service, "_execute_gedcom_import", _fake_gedcom_import)
|
||||
execution = await service._execute_run(run)
|
||||
assert execution.summary == "GEDCOM imported"
|
||||
|
||||
@@ -29,5 +29,6 @@ class TestPageRegistration:
|
||||
assert "Prompts" in settings_response.text
|
||||
assert "Home Page Text" in settings_response.text
|
||||
assert "Maintenance" in settings_response.text
|
||||
assert "Run GEDCOM Import" in settings_response.text
|
||||
assert "Other settings not shown here" in settings_response.text
|
||||
assert "README.md" not in settings_response.text
|
||||
|
||||
Reference in New Issue
Block a user