diff --git a/unittests/datamodel_string_properties.schema.json b/unittests/datamodel_string_properties.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..a6b3b6f9484c2d2cad24726e0c4f1cbb12919aa8 --- /dev/null +++ b/unittests/datamodel_string_properties.schema.json @@ -0,0 +1,13 @@ +{ + "title": "Dataset", + "description": "", + "type": "object", + + "properties": { + "title": { "type": "string", "description": "full dataset title" }, + "campaign": { "type": "string", "description": "FIXME" }, + "method": { "type": "string", "description": "FIXME" } + }, + + "required": ["title"] +} diff --git a/unittests/test_json_schema_model_parser.py b/unittests/test_json_schema_model_parser.py new file mode 100644 index 0000000000000000000000000000000000000000..46bb8832b4e410775e4b8af7e2494af76ac92d1d --- /dev/null +++ b/unittests/test_json_schema_model_parser.py @@ -0,0 +1,48 @@ +# +# 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_json_schema + + +def test_rt_with_string_properties(): + """Test datamodel parsing of datamodel_string_properties.schema.json""" + + model = parse_model_from_json_schema( + "datamodel_string_properties.schema.json") + assert "Dataset" in model + dataset_rt = model["Dataset"] + assert dataset.description == "" + assert len(dataset.get_properties()) == 3 + + assert dataset_rt.get_property("title") != None + assert dataset_rt.get_property("campaign") != None + assert dataset_rt.get_property("method") != None + + title_prop = dataset_rt.get_property("title") + assert title_prop.datatype == db.TEXT + assert dataset_rt.get_importance(title_prop.name) == db.OBLIGATORY + + campaign_prop = dataset_rt.get_property("campaign") + assert campaign_prop.datatype == db.TEXT + assert dataset_rt.get_importance(campaign_prop.name) == db.RECOMMENDED + + method_prop = dataset_rt.get_property("method") + assert method_prop.datatype == db.TEXT + assert dataset_rt.get_importance(method_prop.name) == db.RECOMMENDED