Skip to content
Snippets Groups Projects
Verified Commit a323f4c0 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

TST: add another test for json-schema parser

parent fee1f8f4
No related branches found
No related tags found
2 merge requests!39Release 0.4.0,!33F json schema datamodel
Pipeline #21043 failed
......@@ -566,7 +566,7 @@ class JsonSchemaParser(Parser):
"""Extends the yaml parser to read in datamodels defined in a json schema."""
# @author Florian Spreckelsen
# @date 2022-02-17
# @review Daniel Hornung 2022-02-18
# @review Timm Fitschen 2022-02-30
def parse_model_from_json_schema(self, filename: str):
"""Return a datamodel created from the definition in the json schema in
......@@ -584,6 +584,7 @@ class JsonSchemaParser(Parser):
"""
# @author Florian Spreckelsen
# @date 2022-02-17
# @review Timm Fitschen 2022-02-30
with open(filename, 'r') as schema_file:
model_dict = json.load(schema_file)
......@@ -603,6 +604,7 @@ class JsonSchemaParser(Parser):
our : DataModel
The datamodel defined in `model_dict`
"""
# @review Timm Fitschen 2022-02-30
if isinstance(model_dict, dict):
model_dict = [model_dict]
......@@ -625,6 +627,7 @@ class JsonSchemaParser(Parser):
return DataModel(self.model.values())
def _get_atomic_datatype(self, elt):
# @review Timm Fitschen 2022-02-30
if elt["type"] == "string":
if "format" in elt and elt["format"] in ["date", "date-time"]:
return db.DATETIME
......@@ -640,6 +643,7 @@ class JsonSchemaParser(Parser):
raise JsonSchemaDefinitionError(f"Unkown atomic type in {elt}.")
def _treat_element(self, elt: dict, name: str):
# @review Timm Fitschen 2022-02-30
force_list = False
if name in self.model:
return self.model[name], force_list
......@@ -664,6 +668,7 @@ class JsonSchemaParser(Parser):
return ent, force_list
def _treat_record_type(self, elt: dict, name: str):
# @review Timm Fitschen 2022-02-30
rt = db.RecordType(name=name)
if "required" in elt:
required = elt["required"]
......@@ -689,6 +694,7 @@ class JsonSchemaParser(Parser):
return rt
def _treat_enum(self, elt: dict, name: str):
# @review Timm Fitschen 2022-02-30
if "type" in elt and elt["type"] == "integer":
raise NotImplementedError(
"Integer-enums are not allowd until "
......@@ -704,6 +710,7 @@ class JsonSchemaParser(Parser):
return rt
def _treat_list(self, elt: dict, name: str):
# @review Timm Fitschen 2022-02-30
if not "items" in elt:
raise JsonSchemaDefinitionError(
......
{
"title": "Dataset",
"type": "object",
"properties": {
"method": { "description": "Missing property type" }
}
}
......@@ -134,6 +134,14 @@ def test_required_no_list():
assert "'Dataset' is not of type 'array'" in str(err.value)
def test_missing_property_type():
"""Exception must be raised when "type" is missing."""
with pytest.raises(JsonSchemaDefinitionError) as err:
parse_model_from_json_schema(
os.path.join(FILEPATH,
"datamodel_missing_property_type.schema.json"))
assert "FIXME" in str(err.value)
def test_enum():
"""Enums are represented in references to records of a specific type."""
# @author Florian Spreckelsen
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment