From 34da56d478e5741984aa17d16968ae6eeef563fe Mon Sep 17 00:00:00 2001
From: fspreck <f.spreckelsen@indiscale.com>
Date: Wed, 16 Mar 2022 18:36:00 +0100
Subject: [PATCH] TST: Add unit test and testfile for enums

---
 .../datamodel_enum_prop.schema.json           | 12 ++++++++++
 unittests/test_json_schema_model_parser.py    | 22 +++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 unittests/json-schema-models/datamodel_enum_prop.schema.json

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 00000000..07b6a146
--- /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 3e258e24..85cb82c0 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"])
-- 
GitLab