Skip to content
Snippets Groups Projects
Verified Commit 3c5c5a1c authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP: Added (failing) test for indirect reference.

Note: It could be that the real issue is just a problem of reference resolution order..
parent d9fed9b2
No related branches found
No related tags found
2 merge requests!100WIP: Filling XLSX: Seems to be working.,!93Filling XLSX: Everything except multiple choice.
Pipeline #48404 failed
......@@ -67,6 +67,8 @@ def main():
do_not_create=["Organisation"])
prepare_datamodel("data/multiple_refs_model.yml", ["Training", "Person"],
"data/multiple_refs_schema.json")
prepare_datamodel("data/indirect_model.yml", ["Wrapper"],
"data/indirect_schema.json")
if __name__ == "__main__":
......
{
"Wrapper": {
"Results": [
{
"year": 2022,
"avg_score": 2.4
},
{
"year": 2023,
"avg_score": 4.2
}
],
"Training": {
"name": "Basic Training",
"url": "www.example.com/training/basic"
}
}
}
Training:
recommended_properties:
url:
datatype: TEXT
description: 'The URL'
Results:
description: "Results for a training"
recommended_properties:
year:
datatype: INTEGER
avg_score:
description: The average score for the linked training.
datatype: DOUBLE
Wrapper:
recommended_properties:
Training:
Results:
datatype: LIST<Results>
{
"type": "object",
"properties": {
"Wrapper": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Wrapper",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Training": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Training",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"url": {
"type": "string",
"description": "The URL"
}
}
},
"Results": {
"description": "Results for a training",
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"description": "Results for a training",
"title": "Results",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"year": {
"type": "integer"
},
"avg_score": {
"description": "The average score for the linked training.",
"type": "number"
}
}
}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
},
"required": [
"Wrapper"
],
"additionalProperties": false,
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
File added
......@@ -78,6 +78,10 @@ def test_fill_xlsx():
template_file=rfp("data/multiple_refs_template.xlsx"),
known_good=rfp("data/multiple_refs_data.xlsx"),
schema=rfp("data/multiple_refs_schema.json"))
fill_and_compare(json_file=rfp("data/indirect_data.json"),
template_file=rfp("data/indirect_template.xlsx"),
known_good=rfp("data/multiple_refs_data.xlsx"),
schema=rfp("data/indirect_schema.json"))
def test_errors():
......
......@@ -232,6 +232,25 @@ def test_model_with_multiple_refs():
_compare_generated_to_known_good(
schema_file=rfp("data/multiple_refs_schema.json"),
known_good=rfp("data/multiple_refs_template.xlsx"),
foreign_keys={'Training': {"__this__": ['date', 'url'],
foreign_keys={"Training": {"__this__": ["date", "url"],
"Organisation": ["name"]}},
outfile=None)
def test_model_with_indirect_reference():
_compare_generated_to_known_good(
schema_file=rfp("data/indirect_schema.json"),
known_good=rfp("data/indirect_template.xlsx"),
foreign_keys={"Wrapper": ["Training.name", "Training.url"]},
outfile=None)
def test_exceptions():
# Foreign keys must be lists
with pytest.raises(ValueError, match="Foreign keys must be a list of strings, but a single "
r"string was given:\n\['Wrapper'\] -> name"):
_compare_generated_to_known_good(
schema_file=rfp("data/indirect_schema.json"),
known_good=rfp("data/multiple_refs_template.xlsx"),
foreign_keys={"Wrapper": {"__this__": "name"}},
outfile=None)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment