def test_keep_both_ids(old, new, expected): class Model(BaseModel): id: str other_identifiers: list[OtherIdentifier] = [] assert merge_people(Model(**old), Model(**new), keep_both_ids=True) == Model(**expected)
def test_simple_merge(old, new, expected): class Model(BaseModel): name: str birth_date: str = "" other_names: list[OtherName] = [] assert merge_people(Model(**old), Model(**new)) == Model(**expected)
def test_merge_extras(): # replace was adding a key like extras._internal_id old = {"extras": {"_internal_id": 123}} new = {} expected = old.copy() class Model(BaseModel): extras: dict = {} assert merge_people(Model(**new), Model(**old)) == expected
def test_merge_with_offices(old, new, expected): class Model(BaseModel): id: str offices: list[Office] = [] assert merge_people(Model(**old), Model(**new)) == Model(**expected)
def test_list_merge(old, new, expected): class Model(BaseModel): other_names: list[OtherName] = [] # note that keep doesn't matter for these assert merge_people(Model(**old), Model(**new), None) == Model(**expected)