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

TST: Add integration test for RTs with subtypes

parent 6007fc62
Branches
Tags
2 merge requests!89ENH: JsonSchemaExporter accepts do_not_create parameter.,!81F schema export references
Pipeline #42800 canceled
...@@ -14,7 +14,7 @@ then ...@@ -14,7 +14,7 @@ then
fi fi
fi fi
OUT=/tmp/crawler.output OUT=/tmp/crawler.output
ls ls
cat pycaosdb.ini cat pycaosdb.ini
python3 -c "import linkahead; print('LinkAhead Version:', linkahead.__version__)" python3 -c "import linkahead; print('LinkAhead Version:', linkahead.__version__)"
rm -rf /tmp/caosdb_identifiable_cache.db rm -rf /tmp/caosdb_identifiable_cache.db
...@@ -57,7 +57,7 @@ echo "./crawl.py -a $RUN_ID /" ...@@ -57,7 +57,7 @@ echo "./crawl.py -a $RUN_ID /"
./crawl.py -a $RUN_ID / | tee "$OUT" ./crawl.py -a $RUN_ID / | tee "$OUT"
set +e set +e
if grep "There where unauthorized changes" "$OUT" if grep "There where unauthorized changes" "$OUT"
then then
echo "There still were unauthorized changes, which should not have happend!" echo "There still were unauthorized changes, which should not have happend!"
echo "Test FAILED" echo "Test FAILED"
exit 1 exit 1
...@@ -96,5 +96,8 @@ python3 -m pytest test_json_schema_datamodel_parser.py ...@@ -96,5 +96,8 @@ python3 -m pytest test_json_schema_datamodel_parser.py
echo "Testing yaml datamodel parser" echo "Testing yaml datamodel parser"
python3 -m pytest test_yaml_parser.py python3 -m pytest test_yaml_parser.py
echo "Testing json-schema exporter"
python3 -m pytest test_json_schema_exporter.py
# Obsolete due to teardown in the above test. # Obsolete due to teardown in the above test.
# echo "/n/n/n YOU NEED TO RESTART THE SERVER TO REDO TESTS!!!" # echo "/n/n/n YOU NEED TO RESTART THE SERVER TO REDO TESTS!!!"
#!/usr/bin/env python
# encoding: utf-8
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2023 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 linkahead as db
from caosadvancedtools.json_schema_exporter import recordtype_to_json_schema as rtjs
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_uniqueness_of_reference_types():
parent_type = db.RecordType(name="ParentType").insert()
int_prop = db.Property(name="IntegerProp", datatype=db.INTEGER).insert()
sub_type = db.RecordType(name="SubType").add_parent(parent_type).add_property(
int_prop, importance=db.RECOMMENDED).insert()
referencing_type = db.RecordType(name="ReferencingType")
referencing_type.add_property(int_prop, importance=db.OBLIGATORY)
referencing_type.add_property(parent_type)
referencing_type.insert()
recA = db.Record(name="RecAParent").add_parent(parent_type).insert()
recB = db.Record(name="RecBSub").add_parent(sub_type).insert()
rt = db.execute_query(f"FIND RECORDTYPE WITH name='{referencing_type.name}'", unique=True)
schema = rtjs(rt)
assert schema["title"] == referencing_type.name
assert schema["type"] == "object"
assert len(schema["required"]) == 1
assert "IntegerProp" in schema["required"]
assert "IntegerProp" in schema["properties"]
assert schema["properties"]["IntegerProp"]["type"] == "integer"
assert parent_type.name in schema["properties"]
assert "oneOf" in schema["properties"][parent_type.name]
one_of = schema["properties"][parent_type.name]["oneOf"]
assert len(one_of) == 2
enum_index = 0
if "enum" not in one_of[enum_index]:
# As in unittests, we can't rely on the order of oneOf.
enum_index = 1 - enum_index
assert "enum" in one_of[enum_index]
assert len(one_of[enum_index]["enum"]) == 2
assert f"{recA.id}, {recA.name}" in one_of[enum_index]["enum"]
assert f"{recB.id}, {recB.name}" in one_of[enum_index]["enum"]
assert one_of[1 - enum_index]["type"] == "object"
# No properties in parent_type
assert len(one_of[1 - enum_index]["properties"]) == 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment