Skip to content
Snippets Groups Projects
Commit 9ab543c8 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

feat(tests): system test for issue 14 (parent updates)

parent a035d56d
No related branches found
No related tags found
2 merge requests!198REL: Release 0.10.0,!190System test for confirming issue #14 (parent updates)
Pipeline #56732 failed
This commit is part of merge request !190. Comments created here will be created in the context of that merge request.
......@@ -28,6 +28,8 @@ from linkahead.cached import cache_clear
from linkahead.utils.register_tests import clear_database, set_test_key
from pytest import fixture, mark, raises
import tempfile
set_test_key("10b128cf8a1372f30aa3697466bb55e76974e0c16a599bb44ace88f19c8f61e2")
......@@ -328,3 +330,80 @@ def test_indiscale_87(clear_database):
print(db.apiutils.compare_entities(rec, retrieved))
assert db.apiutils.empty_diff(rec, retrieved)
print("---")
def test_issue_14(clear_database):
"""
Issue title: Some parent updates are required before inserts
https://gitlab.indiscale.com/caosdb/src/caosdb-crawler/-/issues/14
"""
rt1 = db.RecordType(name="RT1")
rt2 = db.RecordType(name="RT2").insert()
rt1.add_property(rt2, importance=db.OBLIGATORY)
rt1.insert()
r = db.Record()
r.add_parent(rt1)
with tempfile.NamedTemporaryFile() as tmpf:
f = db.File(name="test_parent", path="parent_test/file.txt", file=tmpf.name)
f.insert()
# We create a clean new file object here:
f2 = db.File(name="test_parent", path="parent_test/file.txt", file=tmpf.name)
f2.add_parent(rt2)
r.add_property(name="RT2", value=f2)
# Current state in the database: File without parents
f_test_base = db.File(name="test_parent").retrieve()
assert len(f_test_base.parents) == 0
assert len(db.execute_query("FIND Record")) == 0
ident = CaosDBIdentifiableAdapter()
ident.register_identifiable("RT1", db.RecordType().add_parent(
name="RT1").add_property(name="RT2"))
crawler = Crawler(identifiableAdapter=ident)
crawler.synchronize(crawled_data=[f2, r])
f_test = db.File(name="test_parent").retrieve()
assert len(f_test.parents) == 1
assert f_test.parents[0].name == "RT2"
records = db.execute_query("FIND Record")
assert len(records) == 1
assert records[0].get_property("RT2").value == f_test.id
# Another bug: set id of node?
# def test_issue_14(clear_database):
# """
# Issue title: Some parent updates are required before inserts
#
# https://gitlab.indiscale.com/caosdb/src/caosdb-crawler/-/issues/14
# """
#
# rt1 = db.RecordType(name="RT1")
# rt2 = db.RecordType(name="RT2").insert()
# rt1.add_property(rt2, importance=db.OBLIGATORY)
# rt1.insert()
#
# r = db.Record()
# r.add_parent(rt1)
# with tempfile.NamedTemporaryFile() as tmpf:
# f = db.File(name="test_parent", path="parent_test/file.txt", file=tmpf.name)
# f.insert()
#
# f2 = db.File(name="test_parent").retrieve()
# f2.add_parent(rt2)
# r.add_property(name="RT2", value=f2)
# # cont = db.Container([f2, r])
#
# ident = CaosDBIdentifiableAdapter()
# ident.register_identifiable("R1", db.RecordType().add_parent(
# name="R1").add_property(name="R2"))
# crawler = Crawler(identifiableAdapter=ident)
# crawler.synchronize(crawled_data=[f2, r])
# breakpoint()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment