From bbc92851bc5ef6977c24d8ee952f1f24d5bf4632 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Mon, 24 Apr 2023 11:28:28 +0200 Subject: [PATCH] TST: Add unittest for json schema without top-level entity --- src/caosadvancedtools/models/parser.py | 2 +- .../datamodel_no_toplevel_entity.schema.json | 40 +++++++++++++++++++ unittests/test_json_schema_model_parser.py | 5 +++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 3cc370f4..5848a5e7 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -181,7 +181,7 @@ def parse_model_from_json_schema(filename: str, top_level_recordtype: bool = Tru # @review Daniel Hornung 2022-02-18 parser = JsonSchemaParser() - return parser.parse_model_from_json_schema(filename) + return parser.parse_model_from_json_schema(filename, top_level_recordtype) class Parser(object): diff --git a/unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json b/unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json new file mode 100644 index 00000000..d8d0369a --- /dev/null +++ b/unittests/json-schema-models/datamodel_no_toplevel_entity.schema.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://my-schema-id.net", + "type": "object", + "definitions": { + "uuid": { + "type": [ + "string", + "null" + ], + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" + }, + "datetime": { + "type": "string", + "format": "date-time" + } + }, + "properties": { + { + "title": "Dataset1", + "description": "Some description", + "type": "object", + "properties": { + "title": { + "type": "string", + "description": "full dataset title" + }, + "campaign": { + "type": "string", + "description": "FIXME" + }, + "number_prop": { + "type": "number", + "description": "Some float property" + } + }, + "required": ["title", "number_prop"] + } + } +} diff --git a/unittests/test_json_schema_model_parser.py b/unittests/test_json_schema_model_parser.py index a136f9ba..adc6361c 100644 --- a/unittests/test_json_schema_model_parser.py +++ b/unittests/test_json_schema_model_parser.py @@ -356,3 +356,8 @@ def test_name_property(): assert str(err.value).startswith( "The 'name' property must be string-typed, otherwise it cannot be identified with CaosDB's " "name property.") + + +def test_no_toplevel_entity(): + model = parse_model_from_json_schema(os.path.join( + FILEPATH, "datamodel_no_toplevel_entity.schema.json"), top_level_recordtype=False) -- GitLab