Skip to content
Snippets Groups Projects
Commit 511aeaa7 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

TST: Add unittest for json-schema parser

parent 96cb446d
No related branches found
No related tags found
2 merge requests!39Release 0.4.0,!33F json schema datamodel
{
"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"]
}
#
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment