generated from john/python-template
70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
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
|