From 335b7350b52edb7efa6b1edc35e4fe198b5fb86e Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Tue, 24 Oct 2023 17:27:52 +0200 Subject: [PATCH] TST: Extend unittest --- unittests/test_json_schema_exporter.py | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/unittests/test_json_schema_exporter.py b/unittests/test_json_schema_exporter.py index 9fc597cd..b6ef35e6 100644 --- a/unittests/test_json_schema_exporter.py +++ b/unittests/test_json_schema_exporter.py @@ -270,8 +270,8 @@ def test_rt_with_list_props(): @patch("linkahead.execute_query", new=Mock(side_effect=_mock_execute_query)) def test_rt_with_references(): - """References and lists of references will come later, so test if the errors - are thrown correctly. + """References and lists of references to files will come later, so test if + the errors are thrown correctly. """ @@ -280,11 +280,35 @@ def test_rt_with_references(): schema = rtjs(rt) props = schema["properties"] + assert "RefProp" in props + assert "enum" in props["RefProp"] + assert isinstance(props["RefProp"]["enum"], list) + assert len(props["RefProp"]["enum"]) == len( + db.execute_query("SELECT name, id FROM RECORD")) + len( + db.execute_query("SELECT name, id FROM FILE")) + assert "oneOf" not in props["RefProp"] rt = db.RecordType() rt.add_property(name="RefProp", datatype="OtherType") schema = rtjs(rt) + props = schema["properties"] + assert "RefProp" in props + assert "oneOf" in props["RefProp"] + assert len(props["RefProp"]["oneOf"]) == 2 + enum_index = 0 + if "enum" not in props["RefProp"]["oneOf"][enum_index]: + # We can't really require the order here, so we just know that one of + # the two elements must be the enum, the other the object. + enum_index = 1 - enum_index + assert "enum" in props["RefProp"]["oneOf"][enum_index] + assert isinstance(props["RefProp"]["oneOf"][enum_index]["enum"], list) + assert len(props["RefProp"]["oneOf"][enum_index]["enum"]) == 3 + assert "100, otherA" in props["RefProp"]["oneOf"][enum_index]["enum"] + assert "101, otherB" in props["RefProp"]["oneOf"][enum_index]["enum"] + assert "102" in props["RefProp"]["oneOf"][enum_index]["enum"] + # the other element of oneOf is the OtherType object + assert props["RefProp"]["oneOf"][1 - enum_index]["type"] == "object" rt = db.RecordType() rt.add_property(name="RefProp", datatype=db.LIST(db.REFERENCE)) -- GitLab