From 3cc69d7d5bd9f20049bde6bea41455ac3b8c9f1a Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander@mail-schlemmer.de>
Date: Thu, 16 Dec 2021 14:20:35 +0100
Subject: [PATCH] FIX: bug in compare datatype and importance and unit function

---
 src/newcrawler/crawl.py | 11 +++++------
 unittests/test_tool.py  | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/newcrawler/crawl.py b/src/newcrawler/crawl.py
index 6cf0ea9d..3940f305 100644
--- a/src/newcrawler/crawl.py
+++ b/src/newcrawler/crawl.py
@@ -233,11 +233,11 @@ class Crawler(object):
                 if not identical:
                     break
             for key in comp[0]["properties"]:
-                for attribute in ("datatype", "importance"):
-                    if ("datatype" in comp[0]["properties"][key] and
-                        comp[0]["properties"][key]["datatype"] is not None and
-                        comp[1]["properties"][key]["datatype"] !=
-                            comp[1]["properties"][key]["datatype"]):
+                for attribute in ("datatype", "importance", "unit"):
+                    if (attribute in comp[0]["properties"][key] and
+                        comp[0]["properties"][key][attribute] is not None and
+                        comp[0]["properties"][key][attribute] !=
+                            comp[1]["properties"][key][attribute]):
                         identical = False
                         break
 
@@ -251,7 +251,6 @@ class Crawler(object):
                 del updateList[i]
                 continue
             else:
-                breakpoint()
                 pass
 
         return (insertList, updateList)
diff --git a/unittests/test_tool.py b/unittests/test_tool.py
index 26525c0d..13bca20e 100755
--- a/unittests/test_tool.py
+++ b/unittests/test_tool.py
@@ -290,6 +290,27 @@ def test_crawler_update_list(crawler, ident):
     assert len(insl) == 0
     assert len(updl) == 0
 
+def test_identifiable_update(crawler, ident):
+    # change one value in updateList and then run the synchronization:
+    meas = [r for r in crawler.updateList if r.parents[0].name == "Measurement"][0]
+    meas.get_property("responsible").value = []
+    insl, updl = crawler.synchronize(crawler.updateList)
+    assert len(updl) == 1
+
+def test_identifiable_update2(crawler, ident):
+    # change one unit in updateList and then run the synchronization:
+    meas = [r for r in crawler.updateList if r.parents[0].name == "Measurement"][0]
+    meas.get_property("description").unit = "cm"
+    insl, updl = crawler.synchronize(crawler.updateList)
+    assert len(updl) == 1
+
+def test_identifiable_update3(crawler, ident):
+    # change values of multiple records in updateList and then run the synchronization:
+    meas = [r for r in crawler.updateList if r.parents[0].name == "Measurement"]
+    meas[0].get_property("responsible").value = []
+    meas[3].get_property("responsible").value = []
+    insl, updl = crawler.synchronize(crawler.updateList)
+    assert len(updl) == 2
 
 def test_identifiable_adapter():
     query = IdentifiableAdapter.create_query_for_identifiable(
-- 
GitLab