Skip to content
Snippets Groups Projects

F schema export references

Merged Florian Spreckelsen requested to merge f-schema-export-references into dev
All threads resolved!
1 file
+ 48
0
Compare changes
  • Side-by-side
  • Inline
@@ -43,6 +43,7 @@ def _mock_execute_query(query_string, unique=False, **kwargs):
all_records.extend(other_type_records)
referencing_type_rt = db.RecordType(name="ReferencingType")
referencing_type_rt.add_property(name=other_type_rt.name, datatype=db.LIST(other_type_rt.name))
referencing_type_records = db.Container().extend([
db.Record(id=103).add_parent(referencing_type_rt),
db.Record(id=104, name="referencing").add_parent(referencing_type_rt)
@@ -458,6 +459,53 @@ def test_rt_with_references():
}
validate(example, schema)
rt = db.RecordType(name="ReferenceofReferencesType")
rt.add_property(name="RefRefProp", datatype="ReferencingType")
schema = rtjs(rt)
assert "RefRefProp" in schema["properties"]
ref_ref = schema["properties"]["RefRefProp"]
assert "oneOf" in ref_ref
assert len(ref_ref["oneOf"]) == 2
enum_index = 0
if "enum" not in ref_ref["oneOf"][enum_index]:
enum_index = 1 - enum_index
assert len(ref_ref["oneOf"][enum_index]["enum"]) == 2
assert "103" in ref_ref["oneOf"][enum_index]["enum"]
assert "104, referencing" in ref_ref["oneOf"][enum_index]["enum"]
assert ref_ref["oneOf"][1 - enum_index]["type"] == "object"
assert "OtherType" in ref_ref["oneOf"][1 - enum_index]["properties"]
assert ref_ref["oneOf"][1 - enum_index]["properties"]["OtherType"]["type"] == "array"
items = ref_ref["oneOf"][1 - enum_index]["properties"]["OtherType"]["items"]
assert "oneOf" in items
assert len(items["oneOf"]) == 2
# same as above, we can't rely on the order
enum_index = 0
if "enum" not in items["oneOf"][enum_index]:
enum_index = 1 - enum_index
assert "enum" in items["oneOf"][enum_index]
assert isinstance(items["oneOf"][enum_index]["enum"], list)
assert len(items["oneOf"][enum_index]["enum"]) == 3
assert "100, otherA" in items["oneOf"][enum_index]["enum"]
assert "101, otherB" in items["oneOf"][enum_index]["enum"]
assert "102" in items["oneOf"][enum_index]["enum"]
other_type = items["oneOf"][1 - enum_index]
assert other_type["type"] == "object"
assert "IntegerProp" in other_type["properties"]
assert len(other_type["required"]) == 1
assert "IntegerProp" in other_type["required"]
example = {
"RefRefProp": {
"OtherType": [
"100, otherA",
{"IntegerProp": 12}
]
}
}
validate(example, schema)
rt = db.RecordType()
rt.add_property(name="FileProp", datatype=db.FILE)
Loading