From 0d45980b6b1c592d16fa9bfdf158dd2abbae0b76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Mon, 21 Nov 2022 15:32:49 +0100
Subject: [PATCH] TST: reactivate xfail test

---
 unittests/test_tool.py | 46 +++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/unittests/test_tool.py b/unittests/test_tool.py
index 429265f5..9f49bfb9 100755
--- a/unittests/test_tool.py
+++ b/unittests/test_tool.py
@@ -476,7 +476,6 @@ def test_split_into_inserts_and_updates_with_copy_attr(crawler_mocked_identifiab
     crawler.identifiableAdapter.retrieve_identified_record_for_identifiable.assert_called()
 
 
-@pytest.mark.xfail()
 def test_has_missing_object_in_references(crawler):
     # Simulate remote server content by using the names to identify records
     # There are only two known Records with name A and B
@@ -488,34 +487,31 @@ def test_has_missing_object_in_references(crawler):
                                                }))
 
     # one reference with id -> check
-    assert not crawler._has_missing_object_in_references(db.Record(name="C")
-                                                         .add_parent("RTC").add_property('d', 123))
+    assert not crawler._has_missing_object_in_references(
+        Identifiable(name="C", record_type="RTC", properties={'d': 123}))
     # one ref with Entity with id -> check
-    assert not crawler._has_missing_object_in_references(db.Record(name="C")
-                                                         .add_parent("RTC")
-                                                         .add_property('d', db.Record(id=123)
-                                                                       .add_parent("C")))
+    assert not crawler._has_missing_object_in_references(
+        Identifiable(name="C", record_type="RTC", properties={'d': db.Record(id=123)
+                                                              .add_parent("C")}))
     # one ref with id one with Entity with id (mixed) -> check
-    assert not crawler._has_missing_object_in_references(db.Record(name="C").add_parent("RTD")
-                                                         .add_property('d', 123)
-                                                         .add_property('b', db.Record(id=123)
-                                                                       .add_parent("RTC")))
+    assert not crawler._has_missing_object_in_references(
+        Identifiable(name="C", record_type="RTD",
+                     properties={'d': 123, 'b': db.Record(id=123).add_parent("RTC")}))
     # entity to be referenced in the following
     a = db.Record(name="C").add_parent("C").add_property("d", 12311)
     # one ref with id one with Entity without id (but not identifying) -> fail
-    assert not crawler._has_missing_object_in_references(db.Record(name="C").add_parent("RTC")
-                                                         .add_property('d', 123)
-                                                         .add_property('e', a))
+    assert not crawler._has_missing_object_in_references(
+        Identifiable(name="C", record_type="RTC", properties={'d': 123, 'e': a}))
 
     # one ref with id one with Entity without id (mixed) -> fail
-    assert not crawler._has_missing_object_in_references(db.Record(name="D").add_parent("RTD")
-                                                         .add_property('d', 123)
-                                                         .add_property('e', a))
+    assert not crawler._has_missing_object_in_references(
+        Identifiable(name="D", record_type="RTD", properties={'d': 123, 'e': a}))
+
     crawler.add_to_remote_missing_cache(a)
     # one ref with id one with Entity without id but in cache -> check
-    assert crawler._has_missing_object_in_references(db.Record(name="D").add_parent("RTD")
-                                                     .add_property('d', 123)
-                                                     .add_property('e', a))
+    assert crawler._has_missing_object_in_references(
+        Identifiable(name="D", record_type="RTD", properties={'d': 123, 'e': a}))
+
     # if this ever fails, the mock up may be removed
     crawler.identifiableAdapter.get_registered_identifiable.assert_called()
 
@@ -528,7 +524,8 @@ def test_references_entities_without_ids(crawler, ident):
     # id and rec with id
     assert not crawler._has_reference_value_without_id(db.Record().add_parent("Person")
                                                        .add_property('first_name', 123)
-                                                       .add_property('last_name', db.Record(id=123)))
+                                                       .add_property('last_name',
+                                                                     db.Record(id=123)))
     # id and rec with id and one unneeded prop
     assert crawler._has_reference_value_without_id(db.Record().add_parent("Person")
                                                    .add_property('first_name', 123)
@@ -584,6 +581,9 @@ def reset_mocks(mocks):
 
 
 def change_identifiable_prop(ident):
+    """
+    This function is supposed to change a non identifiing property.
+    """
     for ent in ident._records:
         if len(ent.parents) == 0 or ent.parents[0].name != "Measurement":
             continue
@@ -593,10 +593,14 @@ def change_identifiable_prop(ident):
             # change one element; This removes a responsible which is not part of the identifiable
             prop.value = "2022-01-04"
             return
+    # If it does not work, this test is not implemented properly
     raise RuntimeError("Did not find the property that should be changed.")
 
 
 def change_non_identifiable_prop(ident):
+    """
+    This function is supposed to change a non identifiing property.
+    """
     for ent in ident._records:
         if len(ent.parents) == 0 or ent.parents[0].name != "Measurement":
             continue
-- 
GitLab