From 18aef0cfb643367be417bf9613c9e515f0da548c Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander@mail-schlemmer.de>
Date: Fri, 5 May 2023 12:51:47 +0200
Subject: [PATCH] TST: more tests for apiutils

---
 unittests/test_apiutils.py | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py
index bda381cf..b0524e20 100644
--- a/unittests/test_apiutils.py
+++ b/unittests/test_apiutils.py
@@ -101,15 +101,15 @@ def test_compare_entities():
     r2 = db.Record()
     r1.add_parent("bla")
     r2.add_parent("bla")
-    r1.add_parent("lopp")
+    r1.add_parent("lopp")  # r1 has one additional parent
     r1.add_property("test", value=2)
-    r2.add_property("test", value=2)
+    r2.add_property("test", value=2)  # a property with the same value
     r1.add_property("tests", value=3)
-    r2.add_property("tests", value=45)
+    r2.add_property("tests", value=45)  # a property with different value
     r1.add_property("tester", value=3)
-    r2.add_property("tester", )
+    r2.add_property("tester", )  # a property where r2 has no value
     r1.add_property("tests_234234", value=45)
-    r2.add_property("tests_TT", value=45)
+    r2.add_property("tests_TT", value=45)  # one additional property that the other one does not have for both
 
     diff_r1, diff_r2 = compare_entities(r1, r2)
 
@@ -130,6 +130,28 @@ def test_compare_entities():
     assert "tests_234234" in diff_r1["properties"]
     assert "tests_TT" in diff_r2["properties"]
 
+def test_compare_equality():
+    r1 = db.Record()
+    r2 = db.Record()
+    diff_r1, diff_r2 = compare_entities(r1, r2)
+    for i in ("parents", "properties"):
+        assert len(diff_r1[i]) == 0
+        assert len(diff_r2[i]) == 0
+    assert empty_diff(r1, r2)
+
+    r1.add_parent("bla")
+    r2.add_parent("bla")
+    assert empty_diff(r1, r2)
+
+    r1.add_property("test", value=2)
+    r2.add_property("test", value=2)  # a property with the same value
+    diff_r1, diff_r2 = compare_entities(r1, r2)
+    assert empty_diff(r1, r2)
+
+    r1.add_parent("blobb")
+    r2.add_parent("blobb")
+    assert empty_diff(r1, r2)
+
 
 def test_compare_entities_units():
     r1 = db.Record()
-- 
GitLab