diff --git a/unittests/test_yaml_model_parser.py b/unittests/test_yaml_model_parser.py index d6dbf718dfa539e97214c2329cccc5a6bbf172b6..574b41da25e40984c0a1eef62f39080c88f1d1e0 100644 --- a/unittests/test_yaml_model_parser.py +++ b/unittests/test_yaml_model_parser.py @@ -27,6 +27,8 @@ from caosadvancedtools.models.parser import (TwiceDefinedException, parse_model_from_string, parse_model_from_yaml) +from linkahead.apiutils import compare_entities + def to_file(string): f = NamedTemporaryFile(mode="w", delete=False) @@ -641,3 +643,71 @@ RT2: </RecordType> , 'bar': <RecordType name="bar"/> }""" + + +def test_comparison_yaml_model(): + """ + Test for this issue: + https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/130 + """ + model_string = """ +foo: + datatype: INTEGER + description: bla bla + unit: m + +RT1: + obligatory_properties: + foo: + RT2: + test_reference: + +RT2: + +test_reference: + datatype: RT2 + """ + model = parse_model_from_string(model_string) + + # Without the fix, foo will have no datatype, description and no unit **as part of RT1**, so the + # comparison with a version taken from a LinkAhead instance will have these attributes. + # Furthermore, RT2 will be set as the datatype **in object version** in the yaml definition, while + # it is an ID in case of the version from the LinkAhead instance. + + p_foo = db.Property(name="foo", datatype="INTEGER", description="bla bla", unit="m") + rt2 = db.RecordType(name="RT2") + rt1 = db.RecordType(name="RT1") + rt1.add_property(p_foo) + rt1.add_property(rt2) + + server_response = """ +<Entities> + <noscript> + </noscript> + <Property id="2272" name="foo" description="bla bla" datatype="INTEGER" unit="m"> + <Version id="7819eedaeba2aa7305e10c96e8cf7b9ac84aea4a" head="true"/> + </Property> + <RecordType id="2273" name="RT1"> + <Version id="0c1b9df6677ee40d1e1429b2123e078ee6c863e0" head="true"/> + <Property id="2272" name="foo" description="bla bla" datatype="INTEGER" unit="m" importance="OBLIGATORY" flag="inheritance:FIX"/> + <Property id="2274" name="RT2" datatype="RT2" importance="OBLIGATORY" flag="inheritance:FIX"/> + <Property id="2275" name="test_reference" datatype="RT2" importance="OBLIGATORY" flag="inheritance:FIX"/> + </RecordType> + <RecordType id="2274" name="RT2"> + <Version id="185940642680a7eba7f71914dd8dd7758dd13faa" head="true"/> + </RecordType> + <Property id="2275" name="test_reference" datatype="RT2"> + <Version id="03cf86061c78a079b376394dfecdf32566b72fb7" head="true"/> + </Property> +</Entities>""" + + entities = db.Container.from_xml(server_response) + + c1 = compare_entities(model["foo"], entities[0]) + c2 = compare_entities(model["RT1"], entities[1]) + c3 = compare_entities(model["RT2"], entities[2]) + c4 = compare_entities(model["test_reference"], entities[3]) + + + +