diff --git a/unittests/test_issues.py b/unittests/test_issues.py index ad66aa1413303a16b96ed877f3279a061a0a4bc5..40f50c8efe3a1888ebd85125cb018d45d3d3b445 100644 --- a/unittests/test_issues.py +++ b/unittests/test_issues.py @@ -22,7 +22,10 @@ from pytest import mark +import caosdb as db + from caoscrawler.crawl import Crawler +from caoscrawler.identifiable_adapters import CaosDBIdentifiableAdapter from caoscrawler.structure_elements import DictElement from test_tool import rfp @@ -68,3 +71,40 @@ def test_issue_10(): assert records[0].parents[0].name == "TestRec" assert records[0].get_property("float_prop") is not None assert float(records[0].get_property("float_prop").value) == 4.0 + + +def test_issue_39(): + """Test for merge conflicts in + `crawl.Crawler.split_into_inserts_and_updates` (see + https://gitlab.com/caosdb/caosdb-crawler/-/issues/39). + + """ + + crawler = Crawler(debug=True) + + # For trying and failing to retrieve remotely identified records + def _fake_retrieve(*args, **kwargs): + return None + + ident = CaosDBIdentifiableAdapter() + # identifiable property is just name for both Record Types + ident.register_identifiable("RT_A", db.RecordType().add_parent( + name="RT_A").add_property(name="name")) + ident.register_identifiable("RT_B", db.RecordType().add_parent( + name="RT_B").add_property(name="name")) + # overwrite retrieve + ident.retrieve_identified_record_for_identifiable = _fake_retrieve + crawler.identifiableadapter = ident + + # a1 (has id) references b1 (has no id) + a1 = db.Record(name="A", id=101).add_parent(name="RT_A") + b1 = db.Record(name="B").add_parent(name="RT_B") + + # a2 (no id) references b2 (has id) + a2 = db.Record(name="A").add_parent(name="RT_A") + b2 = db.Record(name="B", id=102).add_parent(name="RT_B") + + flat_list = [b2, a2, a1, b1] + + ins, ups = crawler.split_into_inserts_and_updates(flat_list) + print(ins)