From 3af22cc528744a9f4b0660b40164ec86478fe62c Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Tue, 3 Dec 2024 15:25:51 +0100
Subject: [PATCH] TST: Add unittests for
 https://gitlab.com/linkahead/linkahead-pylib/-/issues/119

---
 unittests/test_apiutils.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py
index fdd5adda..6667089a 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"]
-- 
GitLab