diff --git a/integrationtests/test.sh b/integrationtests/test.sh index 1c0357e265eec770069166e614fc0a3aa6ecc548..e97596980918c08567cc2c8ca17dd3387e343c29 100755 --- a/integrationtests/test.sh +++ b/integrationtests/test.sh @@ -82,5 +82,8 @@ python3 -m pytest test_crawl_with_datamodel_problems.py echo "Testing table export" python3 -m pytest test_base_table_exporter_integration.py +echo "Testing yaml datamodel parser" +python3 -m pytest test_yaml_parser.py + # Obsolete due to teardown in the above test. # echo "/n/n/n YOU NEED TO RESTART THE SERVER TO REDO TESTS!!!" diff --git a/integrationtests/test_yaml_parser.py b/integrationtests/test_yaml_parser.py new file mode 100644 index 0000000000000000000000000000000000000000..5401367cdea643cd98dbfcc38b51a2cd56067a87 --- /dev/null +++ b/integrationtests/test_yaml_parser.py @@ -0,0 +1,61 @@ +# encoding: utf-8 +# +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2022 Florian Spreckelsen <f.spreckelsen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see <https://www.gnu.org/licenses/>. +# + +import caosdb as db +from caosadvancedtools.models.parser import parse_model_from_string + + +def _delete_everything(): + ents = db.execute_query("FIND ENTITY WITH ID > 99") + if ents: + ents.delete() + + +def setup_module(): + _delete_everything() + + +def teardown_module(): + _delete_everything() + + +def test_name_in_extern(): + """Test adding the internal `name` property as a parent to an existing + property. + + """ + + model = """ +extern: +- name +- test_name +test_name: + inherit_from_suggested: + - name +""" + db.Property(name="test_name", datatype=db.TEXT).insert() + ents = parse_model_from_string(model) + ents.sync_data_model(noquestion=True) + + test_prop = db.Property(name="test_name").retrieve() + name_prop = db.Property(name="name").retrieve() + assert len(test_prop.parents) == 1 + assert test_prop.has_parent(name_prop)