Files
meeting-assistant/tests/test_people_yaml.py

128 lines
3.5 KiB
Python

import pytest
from mka.application.meeting_service import ParticipantInput
from mka.application.people_yaml import (
PeopleYamlError,
export_people_yaml,
import_people_yaml,
)
def sample_people() -> list[ParticipantInput]:
return [
ParticipantInput(
participant_id="participant-35c1528c",
display_name="Martin Tazl",
role="Beirat",
organization="Verwaltungsbeirat",
attendance_status="present",
),
ParticipantInput(
participant_id="participant-56aae811",
display_name="Norbert Hebbelmann",
role="Gast",
organization="Eigentümergemeinschaft",
attendance_status="mentioned_only",
),
]
def test_export_import_round_trip_preserves_all_people_fields() -> None:
people = sample_people()
exported = export_people_yaml(people)
assert exported.startswith("version: 1\npeople:\n")
assert import_people_yaml(exported) == people
assert export_people_yaml(import_people_yaml(exported)) == exported
def test_import_preserves_stable_ids_roles_organizations_and_attendance() -> None:
imported = import_people_yaml(export_people_yaml(sample_people()))
assert [person.participant_id for person in imported] == [
"participant-35c1528c",
"participant-56aae811",
]
assert imported[0].role == "Beirat"
assert imported[1].organization == "Eigentümergemeinschaft"
assert [person.attendance_status for person in imported] == [
"present",
"mentioned_only",
]
@pytest.mark.parametrize("content", ["people: [", b"\xff\xfe"])
def test_malformed_yaml_is_rejected(content: str | bytes) -> None:
with pytest.raises(PeopleYamlError, match="Malformed People YAML"):
import_people_yaml(content)
def test_unsupported_version_is_rejected() -> None:
with pytest.raises(PeopleYamlError, match="Unsupported People YAML version"):
import_people_yaml("version: 2\npeople: []\n")
def test_missing_id_is_rejected() -> None:
content = """\
version: 1
people:
- display_name: Martin Tazl
attendance_status: present
"""
with pytest.raises(PeopleYamlError, match="participant_id"):
import_people_yaml(content)
def test_invalid_id_is_rejected_without_generating_a_replacement() -> None:
content = """\
version: 1
people:
- participant_id: invalid id
display_name: Martin
attendance_status: present
"""
with pytest.raises(PeopleYamlError, match="invalid participant_id"):
import_people_yaml(content)
def test_duplicate_id_is_rejected() -> None:
content = """\
version: 1
people:
- participant_id: martin
display_name: Martin
attendance_status: present
- participant_id: martin
display_name: Martin Duplicate
attendance_status: mentioned_only
"""
with pytest.raises(PeopleYamlError, match="Duplicate participant_id"):
import_people_yaml(content)
def test_invalid_attendance_is_rejected() -> None:
content = """\
version: 1
people:
- participant_id: martin
display_name: Martin
attendance_status: absent
"""
with pytest.raises(PeopleYamlError, match="invalid attendance_status"):
import_people_yaml(content)
def test_failed_import_does_not_mutate_existing_people() -> None:
existing = sample_people()
snapshot = list(existing)
with pytest.raises(PeopleYamlError):
import_people_yaml("version: 1\npeople: not-a-list\n")
assert existing == snapshot