diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e381333581953a15a4fe533ced131121dc0569d..ebd856357bfb25d4e03ee3550458e590f4a38610 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed ### ### Fixed ### +- refactored to work with the new default key word in FIND queries: RECORD ### Security ### diff --git a/integrationtests/test.sh b/integrationtests/test.sh index 36730cc948d308659f01f6153f86a917ab1909d0..9f8d003c9219f7e243fd50c5d846b9a7450b9c7b 100755 --- a/integrationtests/test.sh +++ b/integrationtests/test.sh @@ -43,21 +43,23 @@ mv DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx \ DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back cd .. echo "run crawler" -./crawl.py / | tee $OUT +./crawl.py / | tee "$OUT" # rename the moved file mv extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back \ extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx # check whether there was something UNAUTHORIZED -grep "There where unauthorized changes" $OUT +grep "There where unauthorized changes" "$OUT" # get the id of the run which is the last field of the output string -RUN_ID=$(grep "run id:" $OUT | awk '{ print $NF }') +RUN_ID=$(grep "run id:" "$OUT" | awk '{ print $NF }') echo $RUN_ID echo "run crawler again" echo "./crawl.py -a $RUN_ID /" -./crawl.py -a $RUN_ID / | tee $OUT +./crawl.py -a $RUN_ID / | tee "$OUT" set +e -if grep "There where unauthorized changes" $OUT +if grep "There where unauthorized changes" "$OUT" then + echo "There still were unauthorized changes, which should not have happend!" + echo "Test FAILED" exit 1 fi set -e diff --git a/integrationtests/test_assure_functions.py b/integrationtests/test_assure_functions.py index b1c731dbbf25f33b54fc3a005402f292525d2d05..e04d481f230936ae96b02fe910401f50e7138a01 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 9d79e857fe706d78103ade3b92ee38498a2a1607..5af9caa3e83184f77c37c24073d85ee5aae2184b 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 4b0a6cedc390b1268e8d2d89393e19a27a83b3be..da1824e8c3cdf3f68bb82f8c7f39e6eecb111f92 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 0c6a145afdab682f82af09a17fb9aa0770769959..8623d57d60ded38987953ffaf78b1d30e15a8011 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 7da90844f14cf0d1eaded9d4fc8f37320da46aad..60c09d73e954c39d752b5fa4ae5e272d28000ca1 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 19b1f8ff10e365031d6940c7b904e3656eda2861..1fa5eaa5a4f050d7282b863aae626982ff738c43 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 2949fa81727a6c61a8646a48c249204fa87542d8..5bf168cd25873975d73cbbaa0249f2fd4c21299b 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_datamodel_problems.py b/integrationtests/test_datamodel_problems.py index 3bca302dd2a337cee7fd023ee6a64c5185bc99f5..855170338fbc81493e407fbe235415d60958c0f0 100644 --- a/integrationtests/test_datamodel_problems.py +++ b/integrationtests/test_datamodel_problems.py @@ -39,7 +39,7 @@ def setup_module(): """Clear problem sets and delete possible test entities""" DataModelProblems.missing.clear() try: - db.execute_query("FIND Test*").delete() + db.execute_query("FIND Entity Test*").delete() except Exception as delete_exc: print(delete_exc) diff --git a/integrationtests/test_im_und_export.py b/integrationtests/test_im_und_export.py index 8ea45fd2cebbcb2c3be6c8cb79805204486f7862..407faa1a1d3eb609ffd01b9c78d74f1c6a9b231b 100644 --- a/integrationtests/test_im_und_export.py +++ b/integrationtests/test_im_und_export.py @@ -8,13 +8,14 @@ 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.delete() + if len(recs) > 0: + recs.delete() assert 0 == len(db.execute_query("FIND File which is stored at " "**/poster.pdf")) print("Importing stored elements") @@ -22,7 +23,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 15b851fb5c81611d0faba93edfc58f46f9d75e79..b8dfe349f3dac3be9bb741f937f2be4f73b6b2af 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 bd18ab375437bec02320dcfd269896c2ba7e2bb0..ddebc049f449026400278a26226d341d64e678c8 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 db189b16e5755094ff0d6816aa0806b197b1e883..2b79f9ae7eedaf6e7d6896450a8e7b14e1dc9b30 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/cfood.py b/src/caosadvancedtools/cfood.py index 4a9f955a17fc429deb6cdd10c3645700e579b4df..c0da4f0156dc2af48a4ba80b4d0af69c62cd5c3e 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -807,7 +807,7 @@ class RowCFood(AbstractCFood): def update_identifiables(self): rec = self.identifiables[0] - for key, value in self.item.iteritems(): + for key, value in self.item.items(): if key in self.unique_cols: continue assure_property_is(rec, key, diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py index 7b81b81ee9a717c226de7f3f3c0e5f28e3e6e789..5e84bc8a60c1b358150c4db389efb62656af0631 100644 --- a/src/caosadvancedtools/crawler.py +++ b/src/caosadvancedtools/crawler.py @@ -212,15 +212,14 @@ class Crawler(object): new_cont.insert(unique=False) logger.info("Successfully inserted {} records!".format(len(new_cont))) all_inserts += len(new_cont) - logger.info("Finished with authorized updates.") + logger.info("Finished with authorized inserts.") changes = cache.get_updates(run_id) for _, _, old, new, _ in changes: - new_cont = db.Container() - new_cont = new_cont.from_xml(new) + new_cont = db.Container.from_xml(new) ids = [] - tmp = [] + tmp = db.Container() update_incomplete = False # remove duplicate entities for el in new_cont: @@ -230,14 +229,14 @@ class Crawler(object): else: update_incomplete = True new_cont = tmp - if new[0].version: + if new_cont[0].version: valids = db.Container() nonvalids = db.Container() for ent in new_cont: remote_ent = db.Entity(id=ent.id).retrieve() if ent.version == remote_ent.version: - valids.append(remote_ent) + valids.append(ent) else: update_incomplete = True nonvalids.append(remote_ent) diff --git a/src/caosadvancedtools/export_related.py b/src/caosadvancedtools/export_related.py index 69b588c34cc7c8123ab4291f6d8f76f06e7400be..7ae3a4dbba65faed551f75a1627eb504a3275f48 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 c9b890de570d29e4a013b14ebe4579e956277ed2..bb06823a7398dd4846712077afa0b35d0713185d 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) + f"FIND {role} WITH name={name}", unique=True) break else: raise Exception("Did not find {}".format(name)) diff --git a/src/caosadvancedtools/scifolder/utils.py b/src/caosadvancedtools/scifolder/utils.py index afa671af85506a57a06ad5198bec4495823c76f1..50e897c7d2f19c6269ec622489c5a2c6ce1a28e0 100644 --- a/src/caosadvancedtools/scifolder/utils.py +++ b/src/caosadvancedtools/scifolder/utils.py @@ -154,7 +154,7 @@ def create_files_list(df, ftype): files = [] for indx, src in df.loc[ftype, - pd.notnull(df.loc[ftype])].iteritems(): + pd.notnull(df.loc[ftype])].items(): desc = df.loc[ftype+" description", indx] if pd.notnull(desc): diff --git a/src/caosadvancedtools/table_converter.py b/src/caosadvancedtools/table_converter.py index 76f4dfcdb5f040d81d923289a7a730806ad8681b..4b8591ed009ee8e63b328ad43e0d458b3e805ce7 100644 --- a/src/caosadvancedtools/table_converter.py +++ b/src/caosadvancedtools/table_converter.py @@ -79,7 +79,7 @@ def from_table(spreadsheet, recordtype): rec = db.Record() rec.add_parent(name=recordtype) - for key, value in row.iteritems(): + for key, value in row.items(): if key.lower() == "description": rec.description = value continue diff --git a/src/caosadvancedtools/table_importer.py b/src/caosadvancedtools/table_importer.py index e5f6579fe2826c589f648d1d2812c04d620576f2..1931c0477fc89584aff8f24fb873d0bf9e98553d 100755 --- a/src/caosadvancedtools/table_importer.py +++ b/src/caosadvancedtools/table_importer.py @@ -339,7 +339,7 @@ class TableImporter(): df[key] = df[key].astype(datatype) # Now check each element - for idx, val in df.loc[pd.notnull(df.loc[:, key]), key].iteritems(): + for idx, val in df.loc[pd.notnull(df.loc[:, key]), key].items(): if not isinstance(val, datatype): msg = (