Skip to content
Snippets Groups Projects
Commit 3d9dd212 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

STY:

parent 8cb5cd54
Branches
Tags
2 merge requests!53Release 0.1,!16Add CI pipelines
......@@ -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:
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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)
......@@ -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)
......@@ -13,6 +13,7 @@ from pytest import raises
from jsonschema.exceptions import ValidationError
def rfp(*pathcomponents):
"""
Return full path.
......
......@@ -47,7 +47,7 @@ def crawler():
# def ident(crawler):
# ident = LocalStorageIdentifiableAdapter()
# crawler.identifiableAdapter = ident
# ident.restore_state(rfp("records.xml"))
# ident.register_identifiable(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment