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!
@@ -34,6 +34,7 @@ def _mock_execute_query(query_string, unique=False, **kwargs):
all_records = db.Container()
all_files = db.Container()
other_type_rt = db.RecordType(name="OtherType")
other_type_rt.add_property(name="IntegerProp", datatype=db.INTEGER, importance=db.OBLIGATORY)
other_type_records = db.Container().extend([
db.Record(id=100, name="otherA").add_parent(other_type_rt),
db.Record(id=101, name="otherB").add_parent(other_type_rt),
@@ -41,13 +42,13 @@ def _mock_execute_query(query_string, unique=False, **kwargs):
])
all_records.extend(other_type_records)
if query_string == "FIND RECORD 'OtherType'":
if query_string == "SELECT name, id FROM RECORD 'OtherType'":
return other_type_records
elif query_string == "FIND RECORDTYPE 'OtherType'" and unique is True:
return other_type_rt
elif query_string == "FIND RECORD":
elif query_string == "SELECT name, id FROM RECORD":
return all_records
elif query_string == "FIND FILE":
elif query_string == "SELECT name, id FROM FILE":
return all_files
else:
return db.Container()
@@ -270,8 +271,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.
"""
@@ -279,11 +280,46 @@ def test_rt_with_references():
rt.add_property(name="RefProp", datatype=db.REFERENCE)
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")
rt.add_property(name="OtherTextProp", datatype=db.TEXT)
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"
other_props = props["RefProp"]["oneOf"][1 - enum_index]["properties"]
assert "IntegerProp" in other_props
assert other_props["IntegerProp"]["type"] == "integer"
assert "required" in props["RefProp"]["oneOf"][1 - enum_index]
assert len(props["RefProp"]["oneOf"][1 - enum_index]["required"]) == 1
assert "IntegerProp" in props["RefProp"]["oneOf"][1 - enum_index]["required"]
# The other prop also works as before
assert "OtherTextProp" in props
assert props["OtherTextProp"]["type"] == "string"
rt = db.RecordType()
rt.add_property(name="RefProp", datatype=db.LIST(db.REFERENCE))
@@ -295,6 +331,18 @@ def test_rt_with_references():
schema = rtjs(rt)
rt = db.RecordType()
rt.add_property(name="FileProp", datatype=db.FILE)
with raises(NotImplementedError):
schema = rtjs(rt)
rt = db.RecordType()
rt.add_property(name="FileProp", datatype=db.LIST(db.FILE))
with raises(NotImplementedError):
schema = rtjs(rt)
def test_broken():
Loading