diff --git a/integrationtests/full_test/crawl.py b/integrationtests/full_test/crawl.py index 62ca8eac18475f7778ccc34372cba7dbfbc3587b..5742769cd858df83f7d608eb4e266b698aaf4a51 100755 --- a/integrationtests/full_test/crawl.py +++ b/integrationtests/full_test/crawl.py @@ -58,7 +58,7 @@ if __name__ == "__main__": c = Crawler(use_cache=True, access=access, verbosity=DEBUG, food=[ProjectCFood, - AnalysisCFood, ExperimentCFood, + ExperimentCFood,AnalysisCFood, PublicationCFood, SimulationCFood, ]) c.crawl(files, interactive=False, security_level=UPDATE) diff --git a/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03/README.md b/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03/README.md index 1c3d6935026481fb6a62fce17941d1a02be64314..718098b2f9ef77d7c09ad144941192e6caa384cf 100644 --- a/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03/README.md +++ b/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03/README.md @@ -4,7 +4,7 @@ responsible: description: A description of another example analysis. source: -- filename: "/ExperimentalData/TestProject/2019-02-03/*.dat" +- filename: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat" description: an example reference to a results file scripts: diff --git a/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.md b/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.md index c62e216b51144cb741e0363c4ce82c5d3e7f7bc7..67b81e22acd600ebdf73cb3b61421a3d7b4d98ff 100644 --- a/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.md +++ b/integrationtests/full_test/extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.md @@ -8,7 +8,7 @@ results: description: an example reference to a results file source: -- filename: /ExperimentalData/TestProject/2019-02-03_something/ +- filename: /ExperimentalData/2010_TestProject/2019-02-03_something/ description: an example reference to an experiment revisionOf: diff --git a/integrationtests/full_test/extroot/ExperimentalData/2010_TestProject/2019-02-03/README.md b/integrationtests/full_test/extroot/ExperimentalData/2010_TestProject/2019-02-03/README.md index 348a6fec3c00ad19a28a9e6b86e668aa36cd73eb..d46cdb4fbbba12fb6a5f106533b72382466f3e89 100644 --- a/integrationtests/full_test/extroot/ExperimentalData/2010_TestProject/2019-02-03/README.md +++ b/integrationtests/full_test/extroot/ExperimentalData/2010_TestProject/2019-02-03/README.md @@ -4,6 +4,6 @@ responsible: description: A description of another example experiment. results: -- filename: "/ExperimentalData/TestProject/2019-02-03/*.dat" +- filename: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat" description: an example reference to a results file ... diff --git a/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md b/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md index 68bebf70be96d400a5e9bc31eb78adbb7168bb23..27196a3d62d62c48f85d4810152fcf0608e64db4 100644 --- a/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md +++ b/integrationtests/full_test/extroot/Publications/Posters/2019-02-03_really_cool_finding/README.md @@ -4,7 +4,7 @@ responsible: description: A description of another example experiment. source: -- /home/professional/CaosDB/caosdb-deploy/profiles/empty/custom/extroot/DataAnalysis/TestProject/2019-02-03/results.pdf +- /home/professional/CaosDB/caosdb-deploy/profiles/empty/custom/extroot/DataAnalysis/2010_TestProject/2019-02-03/results.pdf results: - "*.pdf" diff --git a/integrationtests/full_test/extroot/SimulationData/2010_TestProject/2019-02-03_something/README.md b/integrationtests/full_test/extroot/SimulationData/2010_TestProject/2019-02-03_something/README.md index 3c984cb2246af2b31013295dfaa48cc3e0094d23..feaf7e2a1a4abe78c5534364385fd1c9e93fb169 100644 --- a/integrationtests/full_test/extroot/SimulationData/2010_TestProject/2019-02-03_something/README.md +++ b/integrationtests/full_test/extroot/SimulationData/2010_TestProject/2019-02-03_something/README.md @@ -16,7 +16,7 @@ revisonOf: - ../2019-02-03 source: -- /extroot/ExperimentalData/TestProject/2019-02-03 +- /extroot/ExperimentalData/2010_TestProject/2019-02-03 tags: - collagen diff --git a/integrationtests/full_test/model.yml b/integrationtests/full_test/model.yml index 6fd888dc2f599639ce52af7ff9be17f6a03354fd..03439408526d02e7a14329e075514bb73cf783f9 100644 --- a/integrationtests/full_test/model.yml +++ b/integrationtests/full_test/model.yml @@ -23,11 +23,11 @@ responsible: datatype: REFERENCE results: datatype: REFERENCE -data: +source: datatype: REFERENCE scripts: datatype: REFERENCE -Source: +SourceCode: Simulation: obligatory_properties: date: diff --git a/integrationtests/full_test/test_crawler.py b/integrationtests/full_test/test_crawler.py index 70821deb9e0ae8fbfe286f7e94e73ec00bc5da3d..280ef2624b9548f0e3a7ca9159f21d6321c8d482 100755 --- a/integrationtests/full_test/test_crawler.py +++ b/integrationtests/full_test/test_crawler.py @@ -24,7 +24,7 @@ class CrawlerTest(unittest.TestCase): # There should be a Project with name TestProject which is referenced project_id = exp.get_property("Project").value project = get_entity_with_id(project_id) - assert project.name == "TestProject" + assert project.name == "2010_TestProject" assert "Project" in [p.name for p in project.get_parents()] # There should be a datafile as result attached with path datafile.dat @@ -86,27 +86,21 @@ class CrawlerTest(unittest.TestCase): datfile = get_entity_with_id(datfile_id) assert os.path.basename(datfile.path) == "plot.py" - # There should be a file as script attached with path plot.py - datfile_id = ana.get_property("source").value[0] - datfile = get_entity_with_id(datfile_id) - assert os.path.basename(datfile.path) == "datafile.dat" - self.assertEqual(datfile.description, - "an example reference to a results file") - # Should have a responsible person self.assertIsNotNone(ana.get_property("Responsible")) - person = db.Record(id=ana.get_property("Responsible").value) + person = db.Record(id=ana.get_property("Responsible").value[0]) person.retrieve() - self.assertEqual("Only", person.get_property("FirstName").value) + print(person) + self.assertEqual("Only", person.get_property("firstname").value) # Should have a description self.assertIsNotNone(ana.description) # Should reference an experiment self.assertIsNotNone(ana.get_property("Experiment")) - person = db.Record(id=ana.get_property("Responsible").value) - person.retrieve() - self.assertEqual("2019-02-03", person.get_property("date").value) + exp = db.Record(id=ana.get_property("Experiment").value[0]) + exp.retrieve() + self.assertEqual("2019-02-03", exp.get_property("date").value) ####################### # # second analysis # # @@ -125,9 +119,9 @@ class CrawlerTest(unittest.TestCase): # Should reference an experiment self.assertIsNotNone(ana.get_property("Experiment")) - person = db.Record(id=ana.get_property("Responsible").value) - person.retrieve() - self.assertEqual("2019-02-03", person.get_property("date").value) + exp = db.Record(id=ana.get_property("Experiment").value[0]) + exp.retrieve() + self.assertEqual("2019-02-03", exp.get_property("date").value) def test_simulation(self): ###################### @@ -168,7 +162,7 @@ class CrawlerTest(unittest.TestCase): "FIND Simulation with date=2019-02-03 and identifier='something'", unique=True) - # There should be a file as script attached with path plot.py + # There should be a file as script attached exp = get_entity_with_id(sim.get_property("source").value) self.assertEqual(exp.parents[0].name, "Experiment") @@ -215,8 +209,8 @@ class CrawlerTest(unittest.TestCase): datfile = get_entity_with_id(datfile_id) assert os.path.basename(datfile.path) == "poster.pdf" - # There should be a file as data attached with path plot.py - datfile_id = pub.get_property("sources").value[0] + # There should be a file as data attached + datfile_id = pub.get_property("source").value[0] datfile = get_entity_with_id(datfile_id) assert os.path.basename(datfile.path) == "results.pdf" @@ -228,8 +222,8 @@ class CrawlerTest(unittest.TestCase): ########################## pub = db.execute_query("FIND *paper_on_exciting_stuff ", unique=True) - # There should be a file as data attached with path plot.py - datfile_id = pub.get_property("sources").value[0] + # There should be a file as data attached + datfile_id = pub.get_property("source").value[0] datfile = get_entity_with_id(datfile_id) assert os.path.basename(datfile.path) == "results.pdf" diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py index d0bce391afcac61a5215e77c2636c7b17ed20393..c7a98594abf8ba00952e72eb99f948ed5e9aad43 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -287,6 +287,31 @@ def assure_object_is_in_list(obj, containing_object, property_name, to_be_updated.append(containing_object) +def assure_has_description(entity, description, to_be_updated=None, + verbosity=INFO, force=False): + """ + Checks whether `entity` has the description that is passed. + + If this is the case this function ends. Otherwise the entity is assigned + a new description. The list to_be_updated is supplied, the entity is added to + the list in order to indicate, that the entity `entity` should be updated. + Otherwise it is directly updated + """ + + if entity.description == description: + return + + entity.description = description + + if to_be_updated is None: + if force: + entity.update(unique=False) + else: + guard.safe_update(entity, unique=False) + else: + to_be_updated.append(entity) + + def assure_has_parent(entity, parent, to_be_updated=None, verbosity=INFO, force=False): """ diff --git a/src/caosadvancedtools/utils.py b/src/caosadvancedtools/utils.py index ef902b9ac941afefde3b7cafe6dcf83ad14dea00..843c14ad2f5c9072829c455e7fb955ea6f726d52 100644 --- a/src/caosadvancedtools/utils.py +++ b/src/caosadvancedtools/utils.py @@ -80,7 +80,7 @@ def find_file_included_by(glob): Returns a container. """ - query_string = "FIND file which is stored at '{}'".format(glob) + query_string = "FIND file which is stored at {}".format(glob) try: return db.execute_query(query_string)