From e544bd6515197454f3400f3a5bfda9f6dab7171a Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <alexander@mail-schlemmer.de> Date: Mon, 22 Nov 2021 20:42:29 +0100 Subject: [PATCH] TST: added tests for compare entities --- unittests/test_apiutils.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py index 264b4c88..75110144 100644 --- a/unittests/test_apiutils.py +++ b/unittests/test_apiutils.py @@ -29,7 +29,7 @@ import caosdb as db import pickle import tempfile -from caosdb.apiutils import apply_to_ids, create_id_query, resolve_reference +from caosdb.apiutils import apply_to_ids, create_id_query, resolve_reference, compare_entities import caosdb.apiutils from .test_property import testrecord @@ -102,3 +102,33 @@ def test_resolve_reference(): # restore retrive_entity_with_id caosdb.apiutils.retrieve_entity_with_id = original_retrieve_entity_with_id + + +def test_compare_entities(): + r1 = db.Record() + r2 = db.Record() + r1.add_parent("bla") + r2.add_parent("bla") + r1.add_parent("lopp") + r1.add_property("test", value=2) + r2.add_property("test", value=2) + r1.add_property("tests", value=3) + r2.add_property("tests", value=45) + r1.add_property("tests_234234", value=45) + r2.add_property("tests_TT", value=45) + + diff_r1, diff_r2 = compare_entities(r1, r2) + + assert len(diff_r1["parents"]) == 1 + assert len(diff_r2["parents"]) == 0 + assert len(diff_r1["properties"]) == 2 + assert len(diff_r2["properties"]) == 2 + + assert "test" not in diff_r1["properties"] + assert "test" not in diff_r2["properties"] + + assert "tests" in diff_r1["properties"] + assert "tests" in diff_r2["properties"] + + assert "tests_234234" in diff_r1["properties"] + assert "tests_TT" in diff_r2["properties"] -- GitLab