diff --git a/unittests/json-schema-models/datamodel_enum_prop.schema.json b/unittests/json-schema-models/datamodel_enum_prop.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..07b6a146a3af818da253293cb5744ad3a99d93fc --- /dev/null +++ b/unittests/json-schema-models/datamodel_enum_prop.schema.json @@ -0,0 +1,12 @@ +{ + "title": "Dataset", + "description": "Some description", + "type": "object", + "properties": { + "license": { + "type": "string", + "enum": ["CC-BY", "CC-BY-SA", "CC0", "restricted access"] + } + }, + "required": ["license"] +} diff --git a/unittests/test_json_schema_model_parser.py b/unittests/test_json_schema_model_parser.py index 3e258e244d0f9d58aeae973de00bb0d0c2d19785..85cb82c01901eccc5538ce41d9480913b08284c0 100644 --- a/unittests/test_json_schema_model_parser.py +++ b/unittests/test_json_schema_model_parser.py @@ -126,3 +126,25 @@ def test_required_no_list(): os.path.join(FILEPATH, "datamodel_required_no_list.schema.json")) assert "'Dataset' is not of type 'array'" in str(err.value) + + +def test_enum(): + """Enums are represented in references to records of a specific type.""" + # @author Florian Spreckelsen + # @date 2022-03-16 + + model = parse_model_from_json_schema(os.path.join( + FILEPATH, "datamodel_enum_prop.schema.json")) + licenses = ["CC-BY", "CC-BY-SA", "CC0", "restricted access"] + for name in ["Dataset", "license"] + licenses: + assert name in model + + assert isinstance(model["Dataset"], db.RecordType) + assert model["Dataset"].get_property("license") is not None + assert model["Dataset"].get_property("license").datatype == "license" + assert isinstance(model["license"], db.RecordType) + + for name in licenses: + assert isinstance(model[name], db.Record) + assert len(model[name].parents) == 1 + assert model[name].has_parent(model["license"])