diff --git a/integrationtests/test.py b/integrationtests/test.py index efff64305bbc9dd24ebf7817fb9d10d0523c9f5b..2d8818005ee4350bd3b1403ae71c315c6d5c1a14 100755 --- a/integrationtests/test.py +++ b/integrationtests/test.py @@ -28,6 +28,7 @@ module description """ +import os from caosdb import EmptyUniqueQueryError import argparse import sys @@ -42,7 +43,6 @@ import yaml from caosadvancedtools.testutils import clear_database, set_test_key set_test_key("10b128cf8a1372f30aa3697466bb55e76974e0c16a599bb44ace88f19c8f61e2") -import os def rfp(*pathcomponents): """ @@ -52,14 +52,12 @@ def rfp(*pathcomponents): return os.path.join(os.path.dirname(__file__), *pathcomponents) - - @pytest.fixture def usemodel(): model = parse_model_from_yaml(rfp("model.yml")) model.sync_data_model(noquestion=True, verbose=False) - + @pytest.fixture def ident(): ident = CaosDBIdentifiableAdapter() @@ -68,12 +66,12 @@ def ident(): ident.register_identifiable( "Person", db.RecordType() .add_parent(name="Person") - #.add_property(name="first_name") + # .add_property(name="first_name") .add_property(name="last_name")) ident.register_identifiable( "Measurement", db.RecordType() .add_parent(name="Measurement") - #.add_property(name="identifier") + # .add_property(name="identifier") .add_property(name="date") .add_property(name="project")) ident.register_identifiable( @@ -150,6 +148,7 @@ def test_multiple_insertions(clear_database, usemodel, ident, crawler): assert len(ins) == 0 assert len(ups) == 0 + def test_insertion(clear_database, usemodel, ident, crawler): ins, ups = crawler.synchronize() @@ -169,6 +168,7 @@ def test_insertion(clear_database, usemodel, ident, crawler): assert len(ins) == 0 assert len(ups) == 0 + def test_insertion_and_update(clear_database, usemodel, ident, crawler): ins, ups = crawler.synchronize() @@ -184,7 +184,8 @@ def test_insertion_and_update(clear_database, usemodel, ident, crawler): ins, ups = cr.synchronize() assert len(ins) == 0 assert len(ups) == 1 - + + def test_identifiable_update(clear_database, usemodel, ident, crawler): ins, ups = crawler.synchronize() @@ -197,7 +198,7 @@ def test_identifiable_update(clear_database, usemodel, ident, crawler): l = cr.updateList for record in l: if (record.parents[0].name == "Measurement" and - record.get_property("date").value == "2020-01-03"): + record.get_property("date").value == "2020-01-03"): # maybe a bit weird, but add an email address to a measurement record.add_property(name="email", value="testperson@testaccount.test") print("one change") @@ -206,14 +207,13 @@ def test_identifiable_update(clear_database, usemodel, ident, crawler): assert len(ins) == 0 assert len(ups) == 1 - # Test the change within one property: cr = Crawler(debug=True, identifiableAdapter=ident) crawl_standard_test_directory(cr) l = cr.updateList for record in l: if (record.parents[0].name == "Measurement" and - record.get_property("date").value == "2020-01-03"): + record.get_property("date").value == "2020-01-03"): record.add_property(name="email", value="testperson@coolmail.test") print("one change") break @@ -227,7 +227,7 @@ def test_identifiable_update(clear_database, usemodel, ident, crawler): l = cr.updateList for record in l: if (record.parents[0].name == "Measurement" and - record.get_property("date").value == "2020-01-03"): + record.get_property("date").value == "2020-01-03"): record.add_property(name="email", value="testperson@coolmail.test") record.get_property("date").value = "2012-01-02" print("one change") @@ -269,6 +269,7 @@ def test_file_insertion(clear_database, usemodel, ident, crawler_extended): assert len(r) == 1 assert r[0].get_property("ReadmeFile").value == f.id + def test_file_update(clear_database, usemodel, ident, crawler_extended): ins1, ups1 = crawler_extended.synchronize(commit_changes=True) fileList_ins = [r for r in ins1 if r.role == "File"] @@ -288,7 +289,7 @@ def test_file_update(clear_database, usemodel, ident, crawler_extended): res = db.execute_query("Find File") assert len(res) == 11 assert len(res[0].parents) == 0 - + cr2 = Crawler(debug=True, identifiableAdapter=ident) crawl_standard_test_directory(cr2, cfood="scifolder_extended2.yml") @@ -302,7 +303,6 @@ def test_file_update(clear_database, usemodel, ident, crawler_extended): res = db.execute_query("Find File") assert len(res) == 11 assert res[0].parents[0].name == "ProjectMarkdownReadme" - # TODO: Implement file update checks (based on checksum) # Add test with actual file update: diff --git a/src/doc/conf.py b/src/doc/conf.py index 75731285a77f8a30fcb4bfc6be0483c4bba0052a..825f878b2d52947978e2163b5bcff327e5da009d 100644 --- a/src/doc/conf.py +++ b/src/doc/conf.py @@ -3,7 +3,7 @@ # Configuration file for the Sphinx documentation builder. # # Based on the configuration for caosdb-pylib. -# +# # # Copyright (C) 2021 Alexander Schlemmer <alexander.schlemmer@ds.mpg.de> # # This file only contains a selection of the most common options. For a full diff --git a/src/newcrawler/identified_cache.py b/src/newcrawler/identified_cache.py index cba00dd2bfff8a0f886878f532133bb18b1a20de..0b9d7a47bdecc4094edb1296f4c04dfa083a2436 100644 --- a/src/newcrawler/identified_cache.py +++ b/src/newcrawler/identified_cache.py @@ -66,7 +66,6 @@ def _create_hashable_string(identifiable: db.Record): else: tmplist.append(val) value = str(tmplist) - rec_string += "{}:".format(pname) + value return rec_string diff --git a/unittests/test_converters.py b/unittests/test_converters.py index fcc89f2e1467f23accfe47bd52a51d934ccecf91..166f7d516687b5e2d8e8e60321de5084b38e060a 100644 --- a/unittests/test_converters.py +++ b/unittests/test_converters.py @@ -177,7 +177,8 @@ def test_json_converter(converter_registry): test_json = File("testjson.json", rfp( "test_directories", "examples_json", "testjson.json")) - schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_directories", "examples_json", "testjson.schema.json") + schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), + "test_directories", "examples_json", "testjson.schema.json") jsonconverter = JSONFileConverter( definition={"match": "(.*)", "validate": schema_path}, name="TestJSONFileConverter", @@ -228,7 +229,7 @@ def test_json_converter(converter_registry): broken_json = File("brokenjson.json", rfp( "test_directories", "examples_json", "brokenjson.json")) m = jsonconverter.match(broken_json) - + # Doesn't validate because of missing required 'name' property with pytest.raises(ConverterValidationError) as err: children = jsonconverter.create_children(None, broken_json) diff --git a/unittests/test_entity_comparison.py b/unittests/test_entity_comparison.py index 1e22280d893ae7bba301baa61213b5e49eaaba6c..750828bbd00a7142040c95a532246adbc97ca630 100644 --- a/unittests/test_entity_comparison.py +++ b/unittests/test_entity_comparison.py @@ -13,13 +13,13 @@ from newcrawler.crawl import check_identical def test_compare_entities(): record1 = db.Record() record2 = db.Record() - + assert check_identical(record1, record2) record1.add_property(name="type", value="int") assert not check_identical(record1, record2) assert not check_identical(record2, record1) - + record2.add_property(name="type", value="int") assert check_identical(record1, record2) record2.get_property("type").value = "int2" @@ -79,7 +79,8 @@ def test_compare_entities(): for attribute, values in zip(("_checksum", "_size"), (vals[0], vals[1])): setattr(record1, attribute, values[0]) - assert not check_identical(record1, record2) # not identical, because record1 sets the datatype + # not identical, because record1 sets the datatype + assert not check_identical(record1, record2) assert check_identical(record2, record1) # identical, because record2 sets the datatype setattr(record2, attribute, values[1]) @@ -89,5 +90,3 @@ def test_compare_entities(): setattr(record2, attribute, values[0]) assert check_identical(record1, record2) assert check_identical(record2, record1) - - diff --git a/unittests/test_file_identifiables.py b/unittests/test_file_identifiables.py index 234fae20c53e137bf049e496dbe178a30e5de833..ae5c536a8d55ba345f2708625d04fce3a5fff5c2 100644 --- a/unittests/test_file_identifiables.py +++ b/unittests/test_file_identifiables.py @@ -71,5 +71,3 @@ def test_file_identifiable(): with raises(RuntimeError, match=".*unambigiously.*"): records.append(test_record_alsocorrect_path) identified_file = ident.get_file(file_obj) - - diff --git a/unittests/test_schema.py b/unittests/test_schema.py index cac37c758aa838d78eb24435db55b099258900ac..4af29e28782a29360ecc10f342ae2e09ea7ce88a 100644 --- a/unittests/test_schema.py +++ b/unittests/test_schema.py @@ -13,6 +13,7 @@ from pytest import raises from jsonschema.exceptions import ValidationError + def rfp(*pathcomponents): """ Return full path. diff --git a/unittests/test_tool_extended.py b/unittests/test_tool_extended.py index 2361e99373042a5f5ce73b8eb98083f7431d4836..d9f37064589a9d40e2e1e5be8952c430f058b65e 100644 --- a/unittests/test_tool_extended.py +++ b/unittests/test_tool_extended.py @@ -47,7 +47,7 @@ def crawler(): # def ident(crawler): # ident = LocalStorageIdentifiableAdapter() # crawler.identifiableAdapter = ident - + # ident.restore_state(rfp("records.xml")) # ident.register_identifiable(