Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# 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 os
import caosdb as db
from caosadvancedtools.models.parser import parse_model_from_json_schema
def _clear_db():
ents = db.execute_query("FIND ENTITY WITH ID>99")
if ents:
ents.delete()
def setup_module():
_clear_db()
def teardown_module():
_clear_db()
def _load_and_sync(fname):
"""Load datamodel from json schema in fname and synchronize it without asking.
"""
# @author Florian Spreckelsen
# @date 2022-03-23
fpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), fname)
model = parse_model_from_json_schema(fpath)
model.sync_data_model(noquestion=True)
def test_json_parsed_datamodel():
# @author Florian Spreckelsen
# @date 2022-03-23
_load_and_sync("test_datamodel.schema.json")
# RecordType with atomic properties
rt1 = db.execute_query(
"FIND RECORDTYPE TestTypeWithAtomicProps", unique=True)
assert rt1.description == "RecordType with scalar atomic properties"
assert rt1.get_property("simple_text_prop") is not None
assert rt1.get_property("simple_text_prop").datatype == db.TEXT
assert rt1.get_importance("simple_text_prop") == db.OBLIGATORY
# RecordType with references and enums
rt2 = db.execute_query(
"FIND RECORDTYPE TestTypeWithReferencesAndEnum", unique=True)
# Recordtype with lists
rt3 = db.execute_query("FIND RECORDTYPE TestTypeWithLists", unique=True)