diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py index fdd5adda065a563b15008f1b840539c110921b65..6667089abc2d16e59bd97d16f7d0fe75d07afe1b 100644 --- a/unittests/test_apiutils.py +++ b/unittests/test_apiutils.py @@ -991,3 +991,31 @@ def test_describe_diff(): assert "first" not in diffout assert "second" not in diffout + + +def test_diff_without_names(): + """Test compare_entities in case of properties and parents with + ids and without names + (cf. https://gitlab.com/linkahead/linkahead-pylib/-/issues/119). + + """ + + r1 = db.Record(name="Test").add_parent(name="TestType") + r2 = db.Record(name="Test").add_parent(name="TestType") + r2.add_property(id=123, value="Test") + + diff1, diff2 = compare_entities(r1, r2) + assert len(diff1["properties"]) == 0 + assert len(diff2["properties"]) == 1 + assert 123 in diff2["properties"] + assert None not in diff2["properties"] + + r3 = db.Record().add_parent(id=101) + r4 = db.Record().add_parent(id=102) + diff3, diff4 = compare_entities(r3, r4) + assert len(diff3["parents"]) == 1 + assert 101 in diff3["parents"] + assert None not in diff3["parents"] + assert len(diff4["parents"]) == 1 + assert 102 in diff4["parents"] + assert None not in diff3["parents"]