From 44a157fa82f632752f6353cc78c9cdcac7ce5a5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Thu, 6 Apr 2023 10:37:22 +0200
Subject: [PATCH] MAINT: refactor due to new default entity role(RECORD)

---
 integrationtests/test_assure_functions.py     |  8 ++--
 .../test_base_table_exporter_integration.py   |  4 +-
 integrationtests/test_cache.py                |  2 +-
 .../test_crawl_with_datamodel_problems.py     |  2 +-
 integrationtests/test_crawler_basics.py       |  2 +-
 integrationtests/test_crawler_with_cfoods.py  | 40 +++++++++----------
 integrationtests/test_data_model.py           |  2 +-
 integrationtests/test_im_und_export.py        |  6 +--
 integrationtests/test_table.py                |  8 ++--
 integrationtests/update_analysis.py           |  2 +-
 src/caosadvancedtools/cache.py                |  2 +-
 src/caosadvancedtools/export_related.py       |  2 +-
 src/caosadvancedtools/models/parser.py        |  2 +-
 13 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/integrationtests/test_assure_functions.py b/integrationtests/test_assure_functions.py
index b1c731db..e04d481f 100644
--- a/integrationtests/test_assure_functions.py
+++ b/integrationtests/test_assure_functions.py
@@ -33,7 +33,7 @@ from caosadvancedtools.guard import (global_guard, RETRIEVE, UPDATE)
 
 def setup():
     """Delete all test entities."""
-    db.execute_query("FIND Test*").delete(raise_exception_on_error=False)
+    db.execute_query("FIND ENTITY Test*").delete(raise_exception_on_error=False)
 
 
 def setup_module():
@@ -105,13 +105,13 @@ def test_add_to_empty_list():
     db.Record(name="TestReferencingRecord").add_parent(
         referencing_rt).add_property(list_prop, value=[]).insert()
 
-    referenced_rec = db.execute_query("FIND TestReferencedRecord", unique=True)
+    referenced_rec = db.execute_query("FIND ENTITY TestReferencedRecord", unique=True)
     referencing_rec = db.execute_query(
-        "FIND TestReferencingRecord", unique=True)
+        "FIND ENTITY TestReferencingRecord", unique=True)
 
     assure_object_is_in_list(referenced_rec, referencing_rec, list_prop.name)
 
     referencing_rec = db.execute_query(
-        "FIND TestReferencingRecord", unique=True)
+        "FIND ENTITY TestReferencingRecord", unique=True)
     assert referencing_rec.get_property(list_prop.name).value == [
         referenced_rec.id]
diff --git a/integrationtests/test_base_table_exporter_integration.py b/integrationtests/test_base_table_exporter_integration.py
index 9d79e857..5af9caa3 100644
--- a/integrationtests/test_base_table_exporter_integration.py
+++ b/integrationtests/test_base_table_exporter_integration.py
@@ -81,7 +81,7 @@ def insert_entities():
 def setup_module():
     """Clear all test entities"""
     try:
-        db.execute_query("FIND Test*").delete()
+        db.execute_query("FIND ENTITY Test*").delete()
     except BaseException:
         pass
 
@@ -146,7 +146,7 @@ def test_queries():
         "Test_Property_2").value
 
     # test guessing of selector
-    del(export_dict["Test_Property_2"]["selector"])
+    del (export_dict["Test_Property_2"]["selector"])
     my_exporter = te.BaseTableExporter(
         export_dict=export_dict, record=rec1, raise_error_if_missing=True)
     assert my_exporter.export_dict["Test_Property_2"]["selector"] == "Test_Property_2"
diff --git a/integrationtests/test_cache.py b/integrationtests/test_cache.py
index 4b0a6ced..da1824e8 100644
--- a/integrationtests/test_cache.py
+++ b/integrationtests/test_cache.py
@@ -33,7 +33,7 @@ from caosadvancedtools.cache import UpdateCache
 class CacheTest(unittest.TestCase):
     def empty_db(self):
         try:
-            db.execute_query("FIND Test*").delete()
+            db.execute_query("FIND ENTITY Test*").delete()
         except Exception:
             pass
 
diff --git a/integrationtests/test_crawl_with_datamodel_problems.py b/integrationtests/test_crawl_with_datamodel_problems.py
index 0c6a145a..8623d57d 100644
--- a/integrationtests/test_crawl_with_datamodel_problems.py
+++ b/integrationtests/test_crawl_with_datamodel_problems.py
@@ -74,7 +74,7 @@ def test_crawler_with_data_model_problems():
     deleted_entities = {"Experiment", "Poster", "results"}
 
     for ent in deleted_entities:
-        db.execute_query("FIND "+ent).delete()
+        db.execute_query("FIND ENTITY "+ent).delete()
 
     # Do the crawling
     def access(x): return "extroot" + x
diff --git a/integrationtests/test_crawler_basics.py b/integrationtests/test_crawler_basics.py
index 7da90844..60c09d73 100644
--- a/integrationtests/test_crawler_basics.py
+++ b/integrationtests/test_crawler_basics.py
@@ -40,7 +40,7 @@ def setup_module():
     """Clear all test entities.  Allow insertions."""
     guard.set_level(INSERT)
     try:
-        db.execute_query("FIND Test*").delete()
+        db.execute_query("FIND ENTITY Test*").delete()
     except Exception:
         pass
 
diff --git a/integrationtests/test_crawler_with_cfoods.py b/integrationtests/test_crawler_with_cfoods.py
index 19b1f8ff..1fa5eaa5 100755
--- a/integrationtests/test_crawler_with_cfoods.py
+++ b/integrationtests/test_crawler_with_cfoods.py
@@ -30,7 +30,7 @@ from caosdb.apiutils import retrieve_entity_with_id
 
 
 def get_entity_with_id(eid):
-    return db.execute_query("FIND "+str(eid), unique=True)
+    return db.execute_query("FIND ENTITY "+str(eid), unique=True)
 
 
 class LoadFilesTest(unittest.TestCase):
@@ -49,7 +49,7 @@ class CrawlerTest(unittest.TestCase):
         # # dummy for dependency test experiment # #
         ########################
         exp = db.execute_query(
-            "FIND Experiment with date=2019-02-04 and identifier=empty_identifier",
+            "FIND ENTITY Experiment with date=2019-02-04 and identifier=empty_identifier",
             unique=True)
 
         ########################
@@ -59,7 +59,7 @@ class CrawlerTest(unittest.TestCase):
         # vanishing of the property
         # thus an x is used here. Needs to be fixed.
         exp = db.execute_query(
-            "FIND Experiment with date=2019-02-03 and identifier=empty_identifier",
+            "FIND ENTITY Experiment with date=2019-02-03 and identifier=empty_identifier",
             unique=True)
 
         # There should be a Project with name TestProject which is referenced
@@ -99,7 +99,7 @@ class CrawlerTest(unittest.TestCase):
         # # second experiment # #
         #########################
         exp = db.execute_query(
-            "FIND Experiment with date=2019-02-03 and identifier='something'",
+            "FIND ENTITY Experiment with date=2019-02-03 and identifier='something'",
             unique=True)
 
         # Should be the same project
@@ -120,7 +120,7 @@ class CrawlerTest(unittest.TestCase):
         # # first analysis # #
         ######################
         ana = db.execute_query(
-            "FIND Analysis with date=2019-02-03 and identifier='empty_identifier'",
+            "FIND ENTITY Analysis with date=2019-02-03 and identifier='empty_identifier'",
             unique=True)
 
         # There should be a Project with name TestProject which is referenced
@@ -164,7 +164,7 @@ class CrawlerTest(unittest.TestCase):
         # # second analysis # #
         #######################
         ana = db.execute_query(
-            "FIND Analysis with date=2019-02-03 and identifier='something'",
+            "FIND ENTITY Analysis with date=2019-02-03 and identifier='something'",
             unique=True)
 
         # Should be the same project
@@ -197,7 +197,7 @@ class CrawlerTest(unittest.TestCase):
         # # first simulation # #
         ######################
         sim = db.execute_query(
-            "FIND Simulation with date=2019-02-03 and identifier='empty_identifier'",
+            "FIND ENTITY Simulation with date=2019-02-03 and identifier='empty_identifier'",
             unique=True)
 
         # There should be a Project with name TestProject which is referenced
@@ -228,7 +228,7 @@ class CrawlerTest(unittest.TestCase):
         # # second simulation # #
         #########################
         sim = db.execute_query(
-            "FIND Simulation with date=2019-02-03 and identifier='something'",
+            "FIND ENTITY Simulation with date=2019-02-03 and identifier='something'",
             unique=True)
 
         sources = [get_entity_with_id(el) for el in
@@ -273,7 +273,7 @@ class CrawlerTest(unittest.TestCase):
         #########################
         # # first publication # #
         #########################
-        pub = db.execute_query("FIND *really_cool_finding", unique=True)
+        pub = db.execute_query("FIND ENTITY *really_cool_finding", unique=True)
 
         # There should be a file as result attached with path poster.pdf
         datfile_id = pub.get_property("results").value[0]
@@ -291,7 +291,7 @@ class CrawlerTest(unittest.TestCase):
         ##########################
         # # second publication # #
         ##########################
-        pub = db.execute_query("FIND *paper_on_exciting_stuff ", unique=True)
+        pub = db.execute_query("FIND ENTITY *paper_on_exciting_stuff ", unique=True)
 
         # Test type
         self.assertEqual(pub.parents[0].name, "Thesis")
@@ -311,10 +311,10 @@ class CrawlerTest(unittest.TestCase):
         # # first software version # #
         ##############################
         ana = db.execute_query(
-            "FIND Software with version='V1.0-rc1'", unique=True)
+            "FIND ENTITY Software with version='V1.0-rc1'", unique=True)
 
         sw = db.execute_query(
-            "FIND Software with name='2010_TestSoftware'", unique=True)
+            "FIND ENTITY Software with name='2010_TestSoftware'", unique=True)
         assert sw.get_property("alias").value == "TestSoftware"
 
         # The software record should inherit from the correct software
@@ -360,10 +360,10 @@ class CrawlerTest(unittest.TestCase):
         # # second software version # #
         #######################
         ana = db.execute_query(
-            "FIND Software with version='v0.1'", unique=True)
+            "FIND ENTITY Software with version='v0.1'", unique=True)
 
         sw = db.execute_query(
-            "FIND Software with name='2010_TestSoftware'", unique=True)
+            "FIND ENTITY Software with name='2010_TestSoftware'", unique=True)
 
         # The software record should inherit from the correct software
         assert sw.id == ana.get_parents()[0].id
@@ -393,11 +393,11 @@ class CrawlerTest(unittest.TestCase):
         # # third software version # #
         #######################
         ana = db.execute_query(
-            "FIND Software with date='2020-02-04' and not version",
+            "FIND ENTITY Software with date='2020-02-04' and not version",
             unique=True)
 
         sw = db.execute_query(
-            "FIND Software with name='2020NewProject0X'", unique=True)
+            "FIND ENTITY Software with name='2020NewProject0X'", unique=True)
 
         # The software record should inherit from the correct software
         assert sw.id == ana.get_parents()[0].id
@@ -438,11 +438,11 @@ class CrawlerTest(unittest.TestCase):
         # # fourth software version # #
         #######################
         ana = db.execute_query(
-            "FIND Software with date='2020-02-03' and not version",
+            "FIND ENTITY Software with date='2020-02-03' and not version",
             unique=True)
 
         sw = db.execute_query(
-            "FIND Software with name='2020NewProject0X'", unique=True)
+            "FIND ENTITY Software with name='2020NewProject0X'", unique=True)
         assert sw.get_property("alias").value == "NewProject0X"
 
         # The software record should inherit from the correct software
@@ -479,10 +479,10 @@ class CrawlerTest(unittest.TestCase):
         # # fifth software version # #
         ##############################
         ana = db.execute_query(
-            "FIND Software with version='second'", unique=True)
+            "FIND ENTITY Software with version='second'", unique=True)
 
         sw = db.execute_query(
-            "FIND Software with name='2020NewProject0X'", unique=True)
+            "FIND ENTITY Software with name='2020NewProject0X'", unique=True)
         assert sw.get_property("alias").value == "NewProject0X"
 
         # The software record should inherit from the correct software
diff --git a/integrationtests/test_data_model.py b/integrationtests/test_data_model.py
index 2949fa81..5bf168cd 100644
--- a/integrationtests/test_data_model.py
+++ b/integrationtests/test_data_model.py
@@ -57,7 +57,7 @@ class DataModelTest(unittest.TestCase):
 
     def tearDown(self):
         try:
-            tests = db.execute_query("FIND test*")
+            tests = db.execute_query("FIND ENTITY test*")
             tests.delete()
         except Exception:
             pass
diff --git a/integrationtests/test_im_und_export.py b/integrationtests/test_im_und_export.py
index 8ea45fd2..cd6782c2 100644
--- a/integrationtests/test_im_und_export.py
+++ b/integrationtests/test_im_und_export.py
@@ -8,12 +8,12 @@ from caosadvancedtools.import_from_xml import import_xml
 
 if __name__ == "__main__":
     print("Conducting im- and export tests")
-    rec = db.execute_query("FIND 2019-02-03_really_cool_finding", unique=True)
+    rec = db.execute_query("FIND ENTITY 2019-02-03_really_cool_finding", unique=True)
     directory = TemporaryDirectory()
     export_related_to(rec.id, directory=directory.name)
     # delete everything
     print("Clearing database")
-    recs = db.execute_query("FIND entity with id>99")
+    recs = db.execute_query("FIND ENTITY entity with id>99")
     recs.delete()
     assert 0 == len(db.execute_query("FIND File which is stored at "
                                      "**/poster.pdf"))
@@ -22,7 +22,7 @@ if __name__ == "__main__":
 
     # The following tests the existence of some required entities.
     # However, this is not a full list.
-    db.execute_query("FIND 2019-02-03_really_cool_finding", unique=True)
+    db.execute_query("FIND ENTITY 2019-02-03_really_cool_finding", unique=True)
     db.execute_query("FIND RecordType Poster", unique=True)
     db.execute_query("FIND RecordType Analysis", unique=True)
     db.execute_query("FIND RecordType Person", unique=True)
diff --git a/integrationtests/test_table.py b/integrationtests/test_table.py
index 15b851fb..b8dfe349 100644
--- a/integrationtests/test_table.py
+++ b/integrationtests/test_table.py
@@ -34,14 +34,14 @@ if __name__ == "__main__":
 
     table = pd.read_csv("example_table.csv")
 
-    assert 0 == len(db.execute_query("FIND Person with firstname=Henrik"))
+    assert 0 == len(db.execute_query("FIND ENTITY Person with firstname=Henrik"))
     first = table.loc[table.firstName == "Henrik"]
     tcr = TableCrawler(table=first, unique_cols=["firstName", "lastName"],
                        recordtype="Person", interactive=False)
     tcr.crawl(security_level=UPDATE)
-    assert 1 == len(db.execute_query("FIND Person with firstname=Henrik"))
+    assert 1 == len(db.execute_query("FIND ENTITY Person with firstname=Henrik"))
     tcr = TableCrawler(table=table, unique_cols=["firstName", "lastName"],
                        recordtype="Person", interactive=False)
     tcr.crawl(security_level=UPDATE)
-    assert 1 == len(db.execute_query("FIND Person with firstname=Henrik"))
-    assert 1 == len(db.execute_query("FIND Person with firstname=Max"))
+    assert 1 == len(db.execute_query("FIND ENTITY Person with firstname=Henrik"))
+    assert 1 == len(db.execute_query("FIND ENTITY Person with firstname=Max"))
diff --git a/integrationtests/update_analysis.py b/integrationtests/update_analysis.py
index bd18ab37..ddebc049 100644
--- a/integrationtests/update_analysis.py
+++ b/integrationtests/update_analysis.py
@@ -39,7 +39,7 @@ from caosadvancedtools.serverside.generic_analysis import run
 
 
 def main():
-    da = db.execute_query("FIND Analysis with identifier=TEST", unique=True)
+    da = db.execute_query("FIND ENTITY Analysis with identifier=TEST", unique=True)
     run(da)
 
 
diff --git a/src/caosadvancedtools/cache.py b/src/caosadvancedtools/cache.py
index db189b16..2b79f9ae 100644
--- a/src/caosadvancedtools/cache.py
+++ b/src/caosadvancedtools/cache.py
@@ -344,7 +344,7 @@ class UpdateCache(AbstractCache):
         old_ones = db.Container()
 
         for ent in cont:
-            old_ones.append(db.execute_query("FIND {}".format(ent.id),
+            old_ones.append(db.execute_query("FIND ENTITY {}".format(ent.id),
                                              unique=True))
 
         return old_ones
diff --git a/src/caosadvancedtools/export_related.py b/src/caosadvancedtools/export_related.py
index 69b588c3..7ae3a4db 100755
--- a/src/caosadvancedtools/export_related.py
+++ b/src/caosadvancedtools/export_related.py
@@ -99,7 +99,7 @@ def invert_ids(entities):
 def export_related_to(rec_id, directory="."):
     if not isinstance(rec_id, int):
         raise ValueError("rec_id needs to be an integer")
-    ent = db.execute_query("FIND {}".format(rec_id), unique=True)
+    ent = db.execute_query("FIND ENTITY {}".format(rec_id), unique=True)
     cont = recursively_collect_related(ent)
     export(cont, directory=directory)
 
diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py
index c9b890de..658fe5e9 100644
--- a/src/caosadvancedtools/models/parser.py
+++ b/src/caosadvancedtools/models/parser.py
@@ -260,7 +260,7 @@ class Parser(object):
             for role in ("Property", "RecordType", "Record", "File"):
                 if db.execute_query("COUNT {} {}".format(role, name)) > 0:
                     self.model[name] = db.execute_query(
-                        "FIND {} WITH name={}".format(role, name), unique=True)
+                        "FIND ENTITY {} WITH name={}".format(role, name), unique=True)
                     break
             else:
                 raise Exception("Did not find {}".format(name))
-- 
GitLab